coreAnimation与viewAnimation
2015-11-22 16:28
253 查看
// // ViewController.m // CAAnimationAndViewAnimation // // Created by ys on 15/11/22. // Copyright (c) 2015年 ys. All rights reserved. // #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *blackView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // [self diyCACoreAnimation]; // [self viewAnimation1]; // [self viewAnimation2]; [self viewAnimation3]; } /** * 核心动画的问题在于 1.其直接操作layer层,和view层比不够面向对象. * 2.layer的属性均没有改变.图层动画都是假象, 在动画执行过程中, 图层的position属性一直都没有变过 * 因此在实际开发中,除非某些效果难以达到,一般都是使用view实现动画 */ -(void)diyCACoreAnimation { CABasicAnimation *anim = [CABasicAnimation animation]; anim.keyPath = @"position"; anim.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)]; anim.duration = 0.5; anim.removedOnCompletion = NO; anim.fillMode = kCAFillModeForwards; anim.delegate = self; [self.blackView.layer addAnimation:anim forKey:nil]; } -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { //diyCACoreAnimation动画结束后打印一下发现图层的position属性一直都没有变过 NSLog(@"%@",NSStringFromCGPoint(self.blackView.layer.position)); } -(void)viewAnimation1 { [UIView beginAnimations:nil context:nil]; self.blackView.center = CGPointMake(200, 200); [UIView commitAnimations]; NSLog(@"%@",NSStringFromCGPoint(self.blackView.center)); } -(void)viewAnimation2 { [UIView animateWithDuration:1.0 animations:^{ self.blackView.center = CGPointMake(200, 200); } completion:^(BOOL finished) { NSLog(@"%@",NSStringFromCGPoint(self.blackView.center)); }]; } -(void)viewAnimation3 { [UIView transitionWithView:self.blackView duration:10 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ } completion:^(BOOL finished) { }]; } @end
相关文章推荐
- zabbix_3.0安装部署与中文支持 推荐
- POJ 3664 Election Time
- HTML 基础标签demo
- JAVA语法基础之标识符和关键字
- 《Head First设计模式》学习总结
- select2 取值 遍历 设置默认值
- 备份的重要性
- HDU 5569 矩阵的最小贡献 (DP)
- java中解析xml的四种方法
- Java中的clone方法 -- 原型模式
- 本地通知
- 内部类详解
- ThreadDeath 理解
- POJ2985 The k-th Largest Group(平衡树查询第K大)
- 如何优雅的使用EventBus
- php隐藏图片地址一例
- POJ2985 The k-th Largest Group(平衡树查询第K大)
- 使用urllib2实现图片文件下载
- 关于键盘隐藏的问题
- 总结HTML小鱼游戏