UIView

【UIView】

UIView是所有视图的父类,UIView的属性和方法,就是所有视图的属性和方法  UILabel UIbutton  UITextField  UIImageView的父类都是UIView

 

一.坐标系的属性和方法

@property(nonatomic) CGRect            frame;  在父View坐标系中的位置和大小(参照点父控件的坐标系统)

@property(nonatomic) CGRect            bounds; (View在本作标系统中的位置和大小,参照点是自己以0,0)

@property(nonatomic) CGPoint           center;  中心点

个人认为,bounds影响到子view的位置和大小。


二.父子视图的相关属性

@property(nonatomic,readonly) UIView       *superview;

//拿到当前视图的父视图

redLabel.superview.backgroundColor=[UIColor orangeColor];//这个时候redLabel.superview就是我们的self.view





@property(nonatomic,readonly,copy) NSArray *subviews;

//这个方法是获取的子视图,以数组的形式返回

NSArray *array=self.view.subviews;

 subViews这个数组中的顺序是按照子视图的层次排的,最下面的子视图就是第0个元素,最上面的子视图就是最后一个元素

 

 

三.关于同父视图的子视图的层次关系

   

将子视图拿到最上层

    [view bringSubviewToFront:redLabel];

    //将子视图放到最下面

    [view sendSubviewToBack:yellowLabel];

  [view insertSubview:blueLabel atIndex:0];

    //同上

    [view insertSubview:redLabel aboveSubview:yellowLabel];

    //同上

    [view insertSubview:redLabel belowSubview:subviews[1]];

    //交换两个子视图层次

    [view exchangeSubviewAtIndex:0 withSubviewAtIndex:2];

  四.层次与事件接收

1.父视图不能接收事件,则子视图无法接受事件。

2.子视图超出父视图的部分,不能接收事件

3.同一个父视图下,最上面的视图,首先遭遇事件,如果能够响应,就不向下传递事件。如果不能响应,事件向下传递。

五.UIView动画

    ///翻转
    //开始动画
    [UIView beginAnimations:nil context:nil];
    //设置时常
    [UIView setAnimationDuration:1];
    //设置动画淡入淡出
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    //设置代理
    [UIView setAnimationDelegate:self];
    //设置翻转方向
    [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:self.myView cache:YES];
    //动画结束
    //当动画执行结束,执行animationFinished方法
    [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    [UIView commitAnimations];
    
    
    旋转
    
    //创建一个CGAffineTransform  transform对象
    CGAffineTransform  transform;
    //设置旋转度数
    transform = CGAffineTransformRotate(manImageView.transform,M_PI/6.0);
    //动画开始
    [UIView beginAnimations:@"rotate" context:nil ];
    //动画时常
    [UIView setAnimationDuration:2];
    //添加代理
    [UIView setAnimationDelegate:self];
    //获取transform的值
    [manImageView setTransform:transform];
    //关闭动画
    [UIView commitAnimations];
    
    
    
    
   移动

    [UIView beginAnimations:@"move" context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationDelegate:self];
    //改变它的frame的x,y的值
    manImageView.frame=CGRectMake(100,100, 120,100);
    [UIView commitAnimations];
    
    
    
  翻页动画

    [UIView beginAnimations:@"curlUp" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//指定动画曲线类型,该枚举是默认的,线性的是匀速的
    //设置动画时常
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    //设置翻页的方向
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:manImageView cache:YES];
    //关闭动画
    [UIView commitAnimations];
    
    
  缩放
    
    CGAffineTransform  transform;
    transform = CGAffineTransformScale(manImageView.transform,1.2,1.2);
    [UIView beginAnimations:@"scale" context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationDelegate:self];
    [manImageView setTransform:transform];
    [UIView commitAnimations];
    
    
   
    
    根据当前动画形成反向动画
    CGAffineTransform transform;
    transform=CGAffineTransformInvert(manImageView.transform);
    [UIView beginAnimations:@"Invert" context:nil];
    [UIView setAnimationDuration:2];//动画时常
    [UIView setAnimationDelegate:self];
    [manImageView setTransform:transform];//获取改变后的view的transform
    [UIView commitAnimations];//关闭动画
    

   

 

2)其他动画

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
/+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion 
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

六.与layer关系

 所有view都是有一个底层的layer来驱动,layer:侧重于绘制图形,view:侧重于显示并接受电击事件

 继承关系,view继承Nsresponder layer:继承NSObject

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值