1、UIView基础知识整理

UIWindow

makeKeyAndVisible  让window在屏幕上直接显示出来

窗口的优先级:Normal <  StatusBar < Alert。

添加的window默认是隐藏的,设置优先级不起作用,需设置隐藏性为NO;

UIScreen是一个单例类,因为只有一个屏幕

NSStringFromCGRect 将CGRect的x y width height 拼成一个字符串

 

UIView

frame:以父视图为坐标系;

bounds:以自身视图为坐标系;

center:视图的中心坐标

alpha:透明度:0-1;

 

将视图添加到另一个视图的上面

[view1 insertSubview:view3 aboveSubview:view4];

将视图添加到另一个视图的下面

[view1 insertSubview:view3 belowSubview:view4];

插入到下标为1的位置,更改了视图在父视图中的存储位置(数组中的存储顺序)

[view1 insertSubview:view4 atIndex:1];

通过下标交换两个视图的位置

[subView1 exchangeSubviewAtIndex:1 withSubviewAtIndex:2];

把视图移到最上面

[subView1 bringSubviewToFront:subView2];

把视图移动最下面

[subView1 sendSubviewToBack:subView3];

安全移除方法,首先判断父视图是否存在

if (subView2.superview != nil) {

[subView2 removeFromSuperview];

    }

让view隐藏(全局BOOL类型的默认是NO)

view.hidden =YES;

获取superView视图下面的所有子视图

NSArray *subViews = superView.subviews;

for (UIView *view in subViews) {

        view.backgroundColor = [UIColor grayColor];

    }

开启多点触摸

    superView.multipleTouchEnabled = YES;

开启是否响应触摸事件

    superView.userInteractionEnabled = NO;  默认为YES;

 

Transform

颜色的随机产生

视图.backgroundColor = [UIColor colorWithRed:rand()%10*.1 green:rand()%10*.1 blue:rand()%10*.1 alpha:1];

视图的缩放:CGAffineTransformScale

视图的旋转:CGAffineTransformRotate

视图的移动:CGAffineTransformTranslate

视图的还原:CGAffineTransformIdentity

 

Animation

开始动画

[UIView beginAnimations:@"animation2" context:NULL];

设置动画持续时间

[UIView setAnimationDuration:2];

设置动画次数

[UIView setAnimationRepeatCount:5];

设置动画演示速度(默认:前后慢,中间快)

[UIView setAnimationCurve:UIViewAnimationCurveLinear];    //curve:曲线

(此处为动画的执行效果)

设置动画代理对象,进行方法的回调

[UIView setAnimationDelegate:self];

 

设置动画结束之后调用的方法(该方法为动画结束后调用的方法,一般带以下三个参数)

[UIView setAnimationDidStopSelector:@selector(animationDidStop: finished: context:)];

提交动画

[UIView commitAnimations];

 

动画结束后代理调用的回调方法

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag context:(void *)context {

   NSLog(@"动画结束");

}

 

posted @ 2016-04-12 19:45  C_David  阅读(178)  评论(0编辑  收藏  举报