标签:
CATransition动画
1 // MARK: - CATransition动画 2 3 // /* 动画样式 */ 4 // let kCATransitionFade: NSString! //翻页 5 // let kCATransitionMoveIn: NSString! //弹出 6 // let kCATransitionPush: NSString! //推出 7 // let kCATransitionReveal: NSString! //移出 8 // 9 // /* 动画执行的方向 */ 10 // let kCATransitionFromRight: NSString! //右侧 11 // let kCATransitionFromLeft: NSString! //做成 12 // let kCATransitionFromTop: NSString! //上部 13 // let kCATransitionFromBottom: NSString! //底部 14 15 /* 非公开动画效果 */ 16 // "cube" //立方体 17 // "suckEffect" //吸收 18 // "oglFlip" //翻转 19 // "rippleEffect" //波纹 20 // "pageCurl" //卷页 21 // "cameralrisHollowOpen" //镜头开 22 // "cameralrisHollowClose" //镜头关 23 24 //CATransition动画-揭开(Push动画) 25 @IBAction func caAnimationChage1() 26 { 27 var transition = CATransition() 28 transition.duration = 1.0 29 transition.type = kCATransitionPush //推送类型 30 transition.subtype = kCATransitionFromLeft//从左侧 31 self.view.exchangeSubviewAtIndex(1, withSubviewAtIndex: 0) 32 self.view.layer.addAnimation(transition, forKey: nil) 33 34 } 35 36 //CATransition动画-推出 37 @IBAction func caAnimationChage2() 38 { 39 var transition = CATransition() 40 transition.duration = 1.0 41 transition.type = kCATransitionMoveIn 42 transition.subtype = kCATransitionFromTop 43 self.view.exchangeSubviewAtIndex(0, withSubviewAtIndex: 1) 44 self.view.layer.addAnimation(transition, forKey: nil) 45 } 46 47 48 //CATransition动画-平移 49 @IBAction func caTranatate() 50 { 51 //每次都是从前前位置平移 52 self.testImageView.transform=CGAffineTransformTranslate(self.testImageView.transform, -1.9, -1.9)//正负 代表方向 53 54 //每次都从最开始的位置计算平移 55 // self.testImageView.transform=CGAffineTransformMakeTranslation(1.2, 1.2) 56 } 57 58 //CATransition动画-旋转 59 @IBAction func caRotate() 60 { 61 //连续旋转 62 UIView.beginAnimations(nil, context: nil) 63 UIView.setAnimationDuration(2.0)//设置动画时间 64 self.testImageView.transform=CGAffineTransformRotate(self.testImageView.transform, CGFloat(-M_PI/2)) 65 UIView.commitAnimations() 66 67 //独立旋转,以初始位置旋转 68 // self.testImageView.transform=CGAffineTransformMakeRotation(CGFloat(M_PI/6)) 69 } 70 71 //CATransition动画-缩放 72 @IBAction func caScale() 73 { 74 75 //连续缩放 76 UIView.beginAnimations(nil, context: nil) 77 UIView.setAnimationDuration(2.0)//设置动画时间 78 self.testImageView.transform=CGAffineTransformScale(self.testImageView.transform, 1.5, 1.5);//1.0以下缩小,1.0以上放大 79 UIView.commitAnimations() 80 81 //独立缩放,以初始位置缩放 82 // self.testImageView.transform=CGAffineTransformMakeScale(1.2, 1.2) 83 84 } 85 86 //CATransition动画-反转到某个状态 87 @IBAction func caInvert() 88 { 89 self.testImageView.transform=CGAffineTransformIdentity;//返回到初始状态 90 91 //连续反转 92 UIView.beginAnimations(nil, context: nil) 93 UIView.setAnimationDuration(2.0)//设置动画时间 94 self.testImageView.transform=CGAffineTransformConcat(self.testImageView.transform,CGAffineTransformInvert(self.testImageView.transform)); 95 UIView.commitAnimations() 96 97 //独立反转,以初始位置反转 98 // self.testImageView.transform=CGAffineTransformInvert(self.testImageView.transform) 99 }
iOS开发——动画编程Swift篇&(三)CATransition动画
标签:
原文地址:http://www.cnblogs.com/iCocos/p/4559280.html