UIView的对象属性clipsToBounds被称为裁剪属性,如果bool值为yes,这意味着在这个视图上的子view超出父view的部分将不会被显示
userInteractionEnabled是一个交互属性,如果bool值为no,着意味着这个控件的交互事件不会被触发,默认值为yes。UIView的子类UIImageView的交互属性默认为no
UIImageView的对象属性contentMode,它是图像内容的一种填充方式,最常用的是UIViewContentModeScaleAspectFill
随机颜色:[UIColor colorWithRed:(arc4random()%256)/255.0 green:(arc4random()%256)/255.0 blue:(arc4random()%256)/255.0 alpha:1]
UIView对象的一些常见方法
//根据索引插入一个子视图
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview
//将某个子视图发送到最前面
- (void)bringSubviewToFront:(UIView *)view
//将某个子视图发送到最后面
- (void)sendSubviewToBack:(UIView *)view
//将某个视图从父视图里删除
- (void)removeFromSuperview
//view视图将要出现
- (void)viewWillAppear:(BOOL)animated
//view视图已经出现
- (void)viewDidAppear:(BOOL)animated
//view视图将要消失
- (void)viewWillDisappear:(BOOL)animated
//view视图已经消失
- (void)viewDidDisappear:(BOOL)animated
//交换父view里的子view,某个view里的子view都是以数组的方式存在的
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2
UIView的对象属性transform有6个基本值
CG层 Core Graphics 2D效果
在原对象的基础上平移一次:CGAffineTransformMakeTranslation(CGFloat tx,CGFloat ty)//坐标系里的平移值x和y
在原对象或平移后的基础上平移:CGAffineTransformTranslate(CGAffineTransform t,CGFloat tx, CGFloat ty)//t为平移对象的transform属性
eg:penguin.transform = CGAffineTransformTranslate(penguin.transform, -10, 0);
类似的还有
//缩放
CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)
CGAffineTransformScale(CGAffineTransform t,CGFloat sx, CGFloat sy)//t为平移对象的transform属性
//旋转
CGAffineTransformMakeRotation(CGFloat angle)//agele为弧度值
CGAffineTransformRotate(CGAffineTransform t,CGFloat angle)//t为平移对象的transform属性
CA层 Core Animation 3D效果
//平移
CATransform3DMakeTranslation (CGFloat tx,CGFloat ty, CGFloat tz)
CATransform3DTranslate (CATransform3D t, CGFloat tx,CGFloat ty, CGFloat tz)
//缩放
CATransform3DMakeScale (CGFloat sx, CGFloat sy,CGFloat sz)
CATransform3DScale (CATransform3D t, CGFloat sx,CGFloat sy, CGFloat sz)
//旋转
CATransform3DMakeRotation (CGFloat angle, CGFloat x,CGFloat y, CGFloat z)
CATransform3DRotate (CATransform3D t, CGFloat angle,CGFloat x, CGFloat y, CGFloat z)
//阴影
eg:UIImageView *penguin
//绘制阴影
penguin.layer.shadowColor = [[UIColor blueColor] CGColor]//用CGColor类方法装换
//渲染半径
penguin.layer.shadowRadius = 10;
//渲染透明度
penguin.layer.shadowOpacity = 1;
//让bounds渲染
penguin.layer.masksToBounds = YES;
//渲染偏移量
penguin.layer.shadowOffset = cgSizeMake(10,10);
//动画 Animation(方法来自于UIView)
//开始动画
//参数一:指定关键字,一般为空
//参数二:上下文内容,一般为空
+ (void)beginAnimations:(NSString *)animationID context:(void *)context
//设置执行一遍动画效果的时间 以秒为单位
+ (void)setAnimationDuration:(NSTimeInterval)duration
//设置动画的方法
//参数一:动画效果
//参数二:指定某个view发生动画效果
//参数三:是否使用缓存,默认为YES
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache
//给动画设置一个代理
+ (void)setAnimationDelegate:(id)delegate
//设置动画开始时可执行某些操作
+ (void)setAnimationWillStartSelector:(SEL)selector
//设置动画结束时可执行某些操作
+ (void)setAnimationDidStopSelector:(SEL)selector
//设置动画循环次数
+ (void)setAnimationRepeatCount:(float)repeatCount
//提交动画,是动画执行操作的最后一步
+ (void)commitAnimations
//设置UIView对象的一些关于CALayer的值
eg:UIView *view
//圆角半径
view.layer.cornerRadius = 10
//按bounds绘制
view.layer.masksToBounds = YES
//控件边框的宽度
view.layer.borderWidth = 1;
//边框颜色
view.layer.borderColor = [[UIColor redColor] CGColor]
8-19 ViewController(图形操作)

最新推荐文章于 2024-11-01 20:56:35 发布
