- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 200, 100, 100);
btn.backgroundColor = [UIColor redColor];
[self.view addSubview:btn];
[btn setTitle:@"GoBack" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)click:(UIButton *)btn{
NSLog(@"~~~~動畫~~~~~");
#if 0/* CABasicAnimation? */
//position 位置
//rotation? 旋轉
//scale? 縮放
//通過keyPath(建路徑: 對象的屬性也是屬性, 通過獲取屬性中的屬性)
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//持續(xù)時間
animation.duration = 1;
//起始狀態(tài)
animation.fromValue = @(0.5);
//終止狀態(tài)
animation.toValue = @(2);
//重復次數(默認為0)
animation.repeatCount = NSIntegerMax;
//自動恢復(默認為NO)
animation.autoreverses = YES;
//把動畫添加給layer
//? ? [btn.layer addAnimation:animation forKey:@"scale"];
CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation1.duration = 2;
animation1.fromValue = @(0);
animation1.toValue = @(M_PI * 2);
animation1.repeatCount = NSIntegerMax;
animation1.autoreverses = YES;
//? ? [btn.layer addAnimation:animation1 forKey:@"rotation"];
//組動畫
CAAnimationGroup *group = [CAAnimationGroup animation];
//把動畫添加到組中
group.animations = @[animation, animation1];
//重新設置動畫組的屬性
group.duration = 2;
group.repeatCount = NSIntegerMax;
[btn.layer addAnimation:group forKey:@"組動畫"];
#endif
#if 0/* CAtransition */
CATransition *transition = [CATransition animation];
transition.duration = 2;
transition.repeatCount = NSIntegerMax;
//動畫類型
//fade', `moveIn', `push' and `reveal'
/** type
*
*? 各種動畫效果? 其中除了'fade', `moveIn', `push' ,? `reveal',其他屬于私有的API.
*? ↑↑↑上面四個可以分別使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'來調用.
*? @"cube"? ? ? ? ? ? ? ? ? ? 立方體翻滾效果
*? @"moveIn"? ? ? ? ? ? ? ? ? 新視圖移到舊視圖上面
*? @"reveal"
顯露效果(將舊視圖移開,顯示下面的新視圖)
*? @"fade"? ? ? ? ? ? ? ? ? ? 交叉淡化過渡(不支持過渡方向)? ? ? ? ? ? (默認為此效果)
*? @"pageCurl"? ? ? ? ? ? ? ? 向上翻一頁
*? @"pageUnCurl"? ? ? ? ? ? ? 向下翻一頁
*? @"suckEffect"? ? ? ? ? ? ? 收縮效果,類似系統(tǒng)最小化窗口時的神奇效果(不支持過渡方向)
*? @"rippleEffect"? ? ? ? ? ? 滴水效果,(不支持過渡方向)
*? @"oglFlip"? ? ? ? ? ? ? ? ? 上下左右翻轉效果
*? @"rotate"? ? ? ? ? ? ? ? ? 旋轉效果
*? @"push"
*? @"cameraIrisHollowOpen"? ? 相機鏡頭打開效果(不支持過渡方向)
*? @"cameraIrisHollowClose"? ? 相機鏡頭關上效果(不支持過渡方向)
*/
/** type
*
*? kCATransitionFade? ? ? ? ? ? 交叉淡化過渡
*? kCATransitionMoveIn? ? ? ? ? 新視圖移到舊視圖上面
*? kCATransitionPush? ? ? ? ? ? 新視圖把舊視圖推出去
*? kCATransitionReveal? ? ? ? ? 將舊視圖移開,顯示下面的新視圖
*/
transition.type = @"rippleEffect";
//動畫方向
//kCATransitionFromRight kCATransitionFromLeft kCATransitionFromTop kCATransitionFromBottom
transition.subtype = kCATransitionFromRight;
[btn.layer addAnimation:transition forKey:@"go"];
//? ? //組動畫
//? ? CAAnimationGroup *group = [CAAnimationGroup animation];
//? ? //把動畫添加到組中
//? ? group.animations = @[animation, animation1, transition];
//? ? //重新設置動畫組的屬性
//? ? group.duration = 2;
//? ? group.repeatCount = NSIntegerMax;
//? ? [btn.layer addAnimation:group forKey:@"組動畫"];
#endif
}