ios激情详解之动画3D旋转晃动
2015-09-23 22:30
483 查看
// // Created by WDX on 15/9/23. // Copyright (c) 2015年 WDongXu. All rights reserved. // #import "RootViewController.h" @interface RootViewController () @property (nonatomic, retain)UIView *myView; @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self addSubViews]; }
// 初始化 创建视图 - (void)addSubViews { self.myView = [[UIView alloc]initWithFrame:(CGRectMake(100, 100, 100, 100))]; self.myView.backgroundColor = [UIColor redColor]; [self.view addSubview:self.myView]; [_myView release]; // layer是负责显示图层的 // 要更改 咱们看到的图形的形状 需要更该layer // 设置圆角 // 先决条件 变圆 必须是长宽相同 self.myView.layer.cornerRadius = self.myView.frame.size.width / 2; // 设置阴影的颜色 // CGColorRef 图层绘制的颜色 self.myView.layer.shadowColor = [UIColor blackColor].CGColor; // 显示阴影范围 self.myView.layer.shadowOffset = CGSizeMake(10, 10); // 阴影透明度 self.myView.layer.shadowOpacity = 1; // 模糊程度 self.myView.layer.shadowRadius = 50; // 设置边框 self.myView.layer.borderWidth = 10; // 设置边框的颜色 self.myView.layer.borderColor = [UIColor blueColor].CGColor; // layer层动画 // CAKeyframeAnimation抽象类 // CABasicAnimation 基础动画 可以更改大小,旋转等 // CAPropertyAnimation 主要有按照轨迹移动,位置 比如 执行一组动画是使用背景颜色 // 创建一个button UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)]; button.frame = CGRectMake(100, 300, 100, 100); button.backgroundColor = [UIColor blueColor]; [self.view addSubview:button]; [button setTitle:@"点我" forState:(UIControlStateNormal)]; [button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchUpInside)]; }
- (void)actionButton:(UIButton *)button { // [self xyAnimation]; //[self sizeAnimation]; //[self changeBackgroundColor]; // [self positionPoint]; [self huangDongPoint]; [self transform3D]; // [self groupAnimation]; }
// 实现晃动 - (void)huangDongPoint { CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"]; CGFloat center = self.myView.layer.position.x; CGFloat left = center - 10; CGFloat right = center + 10; NSNumber *l = [NSNumber numberWithFloat:left]; NSNumber *c = [NSNumber numberWithFloat:center]; NSNumber *r = [NSNumber numberWithFloat:right]; animation.values = @[l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c]; animation.duration = 1; [self.myView.layer addAnimation:animation forKey:@"huangDong.x"]; }
// 3d旋转 - (void)transform3D { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; // 结束值 animation.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.myView.layer.transform, M_PI, 10, 10, 10)]; // 设置时间 animation.duration = 2; [self.myView.layer addAnimation:animation forKey:@"transform"]; }
相关文章推荐
- iOS本地化国际化多语言支持
- 【iOS】KVC 和 KVO 的使用场景
- iOS9 News 应用
- iOS 开发中实现打电话功能实用代码
- 《ios应用开发详解》1-3章
- 《ios应用开发详解》目录篇
- ios开发,一些注意项和常见错误
- ios开发记录
- iOS开发:navigationcontrol…
- iOS开发:navigationcontrol…
- iOS开发:使用ToolBar切换视图
- iOS开发:NavigationBar
- iOS大典之点击旋转, 点击停止
- ios激情详解之动画页面翻转
- ios实现点击空白处关闭键盘
- IOS 控件的尺寸放大和缩小
- iOS 控件的位置移动
- 【读书笔记】iOS-属性列表
- iOS开发 ----- AFNetWorking
- 【读书笔记】iOS-属性列表