一 UIView
UIView是所有視圖的父類,UIView的所有的屬性和方法,其子類(所有的控件)都能直接使用’
1.1UIView的層次結(jié)構(gòu)
見【Demo】-【1-SuperView SubView】
//1.獲得當(dāng)前視圖的唯一父視圖
NSLog(@"%@",view1.superview);
NSLog(@"%@",view2.superview);
NSLog(@"%@",view3.superview);
//2.獲得視圖的所有子視圖
NSArray *array = superView.subviews;
NSLog(@"%@",array);
//1.在指定的層面插入一個(gè)新視圖
// [superView insertSubview:view4 atIndex:1];
//2.在某個(gè)視圖的下級插入一個(gè)新視圖
// [superView insertSubview:view4 belowSubview:view3];
// 3.在某個(gè)視圖的上級添加一個(gè)新視圖
[superView insertSubview:view4 aboveSubview:view1];
//**************** 非常常用 ***********
//把指定的視圖放在最上層(最前面) [********* 重點(diǎn) *****]
[superView bringSubviewToFront:view1];
//把指定的視圖放在最底層
[superView sendSubviewToBack:view3];
//交換兩個(gè)視圖的位置
[superView exchangeSubviewAtIndex:2 withSubviewAtIndex:3];
//判斷一個(gè)視圖是否是另一個(gè)視圖的子視圖 【了解】
BOOL isResult = [superView isDescendantOfView:self.window];
1.2UIView的事件接收注意事項(xiàng):
父視圖不能接受事件(userInteractionEnabled是一個(gè)BOOL值,YES 可以響應(yīng)用戶交互,NO 不能響應(yīng))
//UILabel默認(rèn)為NO,UIImageView默認(rèn)為NO 不能接受事件
// superView.userInteractionEnabled = NO; 修改對象是否能接受事件
1)父視圖不能接受事件,則子視圖無法接受事件
2)子視圖超過父視圖部分,不能接受事件
3)同一個(gè)父視圖下,最上面的視圖,首先遭遇事件,如果能夠響應(yīng),就不會向下傳遞事件,如果不能響應(yīng),事件向下傳遞。。。以此類推
見【Demo】-【UIView-event】 【重點(diǎn)】
1.3UIView自帶的動畫 【**** 重點(diǎn) **】
見【Demo】-【3-UIViewAnimation】
UIView *view = (UIView *)[self.window viewWithTag:100];
//***************1.UIView自帶動畫的第一種方式
[UIView beginAnimations:nil context:nil]; //開始準(zhǔn)備制作動畫
//設(shè)置動畫時(shí)間
[UIView setAnimationDuration:2];
if (_flag == NO) {
view.frame = CGRectMake(300, 400, 50, 50);
// view.alpha = 0;
view.backgroundColor = [UIColor blackColor]; //中間過程
_flag = YES;
}else{
view.frame = CGRectMake(20, 20, 150, 150);
view.backgroundColor = [UIColor redColor];
// view.alpha = 1;
_flag = NO;
}
//設(shè)置動畫效果
// view.frame = CGRectMake(300, 400, 50, 50);
[UIView commitAnimations]; //提交動畫
//*******************2.UIView自帶動畫的第二種方式
UIView *view = (UIView *)[self.window viewWithTag:100];
[UIView animateWithDuration:2 animations:^{
//設(shè)置動畫效果
view.frame = CGRectMake(300, 480, 10, 10);
//讓視圖做旋轉(zhuǎn)或者縮放的動畫效果
view.transform = CGAffineTransformMakeRotation(M_PI);
}];
不停旋轉(zhuǎn)的寫法:
NSTimer *_timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerStart) userInfo:nil repeats:YES];
方法里面寫:
UIView *view = (UIView *)[self.window viewWithTag:100];
view.transform = CGAffineTransformRotate(view.transform, M_PI/10);
1.4 ??磕J? 指的是控制父視圖改變大小時(shí),子視圖隨著父視圖的大小的變化而變化;