iOS 动画
设置UIview的动画属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | //边框宽度 self .ouroleView.layer.borderWidth=10; //边框颜色 self .ouroleView.layer.borderColor=[UIColor blueColor].CGColor; //圆角 self .ouroleView.layer.cornerRadius=10; //阴影 self .ouroleView.layer.shadowColor=[UIColor blackColor].CGColor; //阴影偏差 self .ouroleView.layer.shadowOffset=CGSizeMake(10, 10); //阴影不透明度 self .ouroleView.layer.shadowOpacity=0.5; //为YES的话 超出边框的部分就给剪掉 self .ouroleView.layer.masksToBounds= NO ; |
设置UIImageView的动画属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | // //边框宽度 // self.imgView.layer.borderWidth=10; // // //边框颜色 // self.imgView.layer.borderColor=[UIColor greenColor].CGColor; //圆角 self .imgView.layer.cornerRadius=10; //阴影 self .imgView.layer.shadowColor=[UIColor blackColor].CGColor; //阴影偏差 self .imgView.layer.shadowOffset=CGSizeMake(10, 10); //阴影不透明度 self .imgView.layer.shadowOpacity=0.5; //为YES的话 超出边框的部分就给剪掉 阴影就会没有 self .imgView.layer.masksToBounds= YES ; //缩放 // self.imgView.layer.transform=CATransform3DMakeScale(1.5, 0.5, 1); //旋转 x y z 确定绕着什么转 // self.imgView.layer.transform=CATransform3DMakeRotation(M_PI_4, 0, 0, 1); |
//创建图层
1 2 3 4 5 6 7 8 9 10 11 | //新建图层 CALayer * layer =[CALayer layer]; layer.backgroundColor=[UIColor redColor].CGColor; layer.bounds=CGRectMake(0, 0, 100, 100); layer.position=CGPointMake(100, 300); layer.cornerRadius=10; layer.contents=(__bridge id )([UIImage imageNamed:@ "a2.jpg" ].CGImage); layer.masksToBounds= YES ; //添加到控制器 [ self .view.layer addSublayer:layer]; |
隐式动画
当对非Root Layer的部分属性进行修改时,默认是自动产生一些动画效果
1 2 3 4 5 6 7 8 9 10 | self .layer =[CALayer layer]; _layer.bounds=CGRectMake(0, 0, 100, 100); _layer.backgroundColor=[UIColor yellowColor].CGColor; _layer.position=CGPointZero; //锚点 决定着CALayer身上的那个点会在position属性所指的位置 _layer.anchorPoint=CGPointZero; [ self .view.layer addSublayer:_layer]; |
在开始点击触碰里面设置事件
1 2 3 4 5 6 7 8 | -( void )touchesBegan:( NSSet *)touches withEvent:(UIEvent *)event{ NSLog (@ "------开始触碰" ); // self.layer.backgroundColor=[UIColor blueColor].CGColor; self .layer.opacity=0.5; } |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步