iOS抽奖转盘动画之CAAnimation动画
2015-10-10 14:00
316 查看
/*CAAnimation
1.基础动画 CABasicAnimation
2.关键帧动画 CAKeyframeAnimation
3.转场动画 CATransition
4.动画组 CAAnimationGroup
*/
导入QuartzCore 头文件 和库
@interface
ViewController ()
//声明一个图层的属性
@property (nonatomic,strong) CALayer *layer;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//创建一个图层
CALayer *layer = [CALayerlayer];
//设置layer的bounds 以自己为中心的坐标x,y都是00
layer.bounds =
CGRectMake(0,
0, 100, 100);
//相对superlayer的位置
layer.position =
CGPointMake(100,
100);
// layer.anchorPoint = CGPointMake(0, 0);
锚点和position是不同坐标系下的同一个位置
layer.backgroundColor = [UIColoryellowColor].CGColor;
//添加到视图的图层上
[self.view.layeraddSublayer:layer];
//赋值给自己的layer属性
self.layer = layer;
}
//通过触摸的方式演示动画
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[selfanimationScale];
}
- (void)animationScale{
//1.创建动画对象 通过类方法创建
CABasicAnimation *anim = [CABasicAnimationanimation];
//2.设置动画 :keyPath 决定了执行怎样的动画执行大小变化的动画
// anim.keyPath = @"backgroundColor";
anim.keyPath =
@"bounds";
//bounds对应的是缩放 position对应的是平移 transform对应的是旋转
//tovalue是到达哪个点 byValue从增加多少值 fromValue 从哪个点开始移动
// anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];
/*创建一个矢量
anim.toValue = [NSValue valueWithCGVector:CGVectorMake(100, 100)];
*/
anim.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,50,
50)];
//动画执行时间
anim.duration =
3.0f;
//动画执行完毕后不移除动画
anim.removedOnCompletion =YES;//如果设置为NO 那么就要设置fillMode来规定动画结束后的状态
//动画状态 决定当前动画在非active时间段的行为 比如动画开始之前动画结束之后
// anim.fillMode = @"forwards";
//3.添加动画到图层上 key是用来标识动画的,应该是唯一的即使是nil
[self.layeraddAnimation:animforKey:nil];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
}
@end
1.基础动画 CABasicAnimation
2.关键帧动画 CAKeyframeAnimation
3.转场动画 CATransition
4.动画组 CAAnimationGroup
*/
导入QuartzCore 头文件 和库
@interface
ViewController ()
//声明一个图层的属性
@property (nonatomic,strong) CALayer *layer;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//创建一个图层
CALayer *layer = [CALayerlayer];
//设置layer的bounds 以自己为中心的坐标x,y都是00
layer.bounds =
CGRectMake(0,
0, 100, 100);
//相对superlayer的位置
layer.position =
CGPointMake(100,
100);
// layer.anchorPoint = CGPointMake(0, 0);
锚点和position是不同坐标系下的同一个位置
layer.backgroundColor = [UIColoryellowColor].CGColor;
//添加到视图的图层上
[self.view.layeraddSublayer:layer];
//赋值给自己的layer属性
self.layer = layer;
}
//通过触摸的方式演示动画
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[selfanimationScale];
}
- (void)animationScale{
//1.创建动画对象 通过类方法创建
CABasicAnimation *anim = [CABasicAnimationanimation];
//2.设置动画 :keyPath 决定了执行怎样的动画执行大小变化的动画
// anim.keyPath = @"backgroundColor";
anim.keyPath =
@"bounds";
//bounds对应的是缩放 position对应的是平移 transform对应的是旋转
//tovalue是到达哪个点 byValue从增加多少值 fromValue 从哪个点开始移动
// anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];
/*创建一个矢量
anim.toValue = [NSValue valueWithCGVector:CGVectorMake(100, 100)];
*/
anim.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,50,
50)];
//动画执行时间
anim.duration =
3.0f;
//动画执行完毕后不移除动画
anim.removedOnCompletion =YES;//如果设置为NO 那么就要设置fillMode来规定动画结束后的状态
//动画状态 决定当前动画在非active时间段的行为 比如动画开始之前动画结束之后
// anim.fillMode = @"forwards";
//3.添加动画到图层上 key是用来标识动画的,应该是唯一的即使是nil
[self.layeraddAnimation:animforKey:nil];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
}
@end
相关文章推荐
- [IOS]对项目重命名
- 【IOS 开发学习总结-OC-39】★★ios开发之 MVC 模式
- iOS 被键盘遮挡时,带有textfield的tableview自动上移
- Customizing Navigation Bar and Status Bar in iOS 7
- ios随机数,and()、random()、arc4random()
- IOS 腾讯微博开放平台 SDK 初体验
- 【iOS】文件上传小记
- IOS 推送
- IOS控件 动画操作 与 CALayer 简单操作
- IOS 系统文字转英文字母
- IOS delegate注册推送
- IOS横屏事件
- IOS汉字排序
- iOS开展-clang: error: unknown argument: '-websockets'解决方案
- iOS流量监控
- ios子控件超过了父控件的frame范围,超过的部分不显示
- iOS开发中@property的属性weak nonatomic strong readonly等介绍
- ios开发中WebView,去除(自定义)JS中Alert显示的网址
- iOS开发4-多控件的使用
- iOS开发之日期