swift的代码教程-ios简单动画类(Animator)

直接上代码,学习使用,请勿喷,谢谢。。,代码已测试可用。

  1. import Foundation  
  2. import UIkit  
  3. import QuartzCore  
  4.   
  5. class Animator{  
  6.      func flipHorizontalViewContorller(nextController: UIViewController!,selfViewController: UIViewController!,back:() -> Void){  
  7.         nextController.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal  
  8.         selfViewController.presentViewController(nextController, animated: true, completion:back)  
  9.     }  
  10.       
  11.     func coverVerticalViewContorller(nextController: UIViewController!,selfViewController: UIViewController!,back:() -> Void){  
  12.         nextController.modalTransitionStyle = UIModalTransitionStyle.CoverVertical  
  13.         selfViewController.presentViewController(nextController, animated: true, completion:back)  
  14.     }  
  15.       
  16.     func crossDissolveViewContorller(nextController: UIViewController!,selfViewController: UIViewController!,back:() -> Void){  
  17.         nextController.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve  
  18.         selfViewController.presentViewController(nextController, animated: true, completion:back)  
  19.     }  
  20.       
  21.     func partialCurlViewContorller(nextController: UIViewController!,selfViewController: UIViewController!,back:() -> Void){  
  22.         nextController.modalTransitionStyle = UIModalTransitionStyle.PartialCurl  
  23.         selfViewController.presentViewController(nextController, animated: true, completion:back)  
  24.     }  
  25.       
  26.     func viewMoveInFromLeft(nextView:UIView!,aniTime:Float!,animoteKey:String!){  
  27.         var animation:CATransition = CATransition()  
  28.         animation.duration = CFTimeInterval(aniTime)  
  29.         animation.type = "moveIn"  
  30.         animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")  
  31.         animation.subtype = "fromLeft"  
  32.         animation.fillMode = "forwards"  
  33.         nextView.layer.addAnimation(animation, forKey: animoteKey)  
  34.     }  
  35.       
  36.     func viewMoveInFromRight(nextView:UIView!,aniTime:Float!,animoteKey:String!){  
  37.         var animation:CATransition = CATransition()  
  38.         animation.duration = CFTimeInterval(aniTime)  
  39.         animation.type = "moveIn"  
  40.         animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")  
  41.         animation.subtype = "fromRight"  
  42.         animation.fillMode = "forwards"  
  43.         nextView.layer.addAnimation(animation, forKey: animoteKey)  
  44.     }  
  45.       
  46.     func viewMoveInFromTop(nextView:UIView!,aniTime:Float!,animoteKey:String!){  
  47.         var animation:CATransition = CATransition()  
  48.         animation.duration = CFTimeInterval(aniTime)  
  49.         animation.type = "moveIn"  
  50.         animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")  
  51.         animation.subtype = "fromTop"  
  52.         animation.fillMode = "forwards"  
  53.         nextView.layer.addAnimation(animation, forKey: animoteKey)  
  54.     }  
  55.       
  56.     func viewMoveInFromBottom(nextView:UIView!,aniTime:Float!,animoteKey:String!){  
  57.         var animation:CATransition = CATransition()  
  58.         animation.duration = CFTimeInterval(aniTime)  
  59.         animation.type = "moveIn"  
  60.         animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")  
  61.         animation.subtype = "fromBottom"  
  62.         animation.fillMode = "forwards"  
  63.         nextView.layer.addAnimation(animation, forKey: animoteKey)  
  64.     }  
  65.       
  66.     func viewFadeOut(nextView:UIView!,aniTime:Float!,animoteKey:String!){  
  67.         var animation:CATransition = CATransition()  
  68.         animation.duration = CFTimeInterval(aniTime)  
  69.         animation.type = "fade"  
  70.         animation.timingFunction = CAMediaTimingFunction(name: "easeOut")  
  71.         animation.fillMode = "forwards"  
  72.         nextView.layer.addAnimation(animation, forKey: animoteKey)  
  73.     }  
  74.       
  75.     func viewFadeIn(nextView:UIView!,aniTime:Float!,animoteKey:String!){  
  76.         var animation:CATransition = CATransition()  
  77.         animation.duration = CFTimeInterval(aniTime)  
  78.         animation.type = "fade"  
  79.         animation.timingFunction = CAMediaTimingFunction(name: "easeIn")  
  80.         animation.fillMode = "forwards"  
  81.         nextView.layer.addAnimation(animation, forKey: animoteKey)  
  82.     }  
  83.       
  84.     func viewFlipFromLeft(view:UIView!,aniTime:Float!){  
  85.         UIView.beginAnimations(nil, context: nil)  
  86.         UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)  
  87.         UIView.setAnimationDuration(NSTimeInterval(aniTime))  
  88.         UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromLeft, forView: view, cache: false)  
  89.         UIView.commitAnimations()  
  90.     }  
  91.       
  92.     func viewFlipFromRight(view:UIView!,aniTime:Float!){  
  93.         UIView.beginAnimations(nil, context: nil)  
  94.         UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)  
  95.         UIView.setAnimationDuration(NSTimeInterval(aniTime))  
  96.         UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromRight, forView: view, cache: false)  
  97.         UIView.commitAnimations()  
  98.     }  
  99.       
  100.     func viewCurup(view:UIView!,aniTime:Float!){  
  101.         UIView.beginAnimations(nil, context: nil)  
  102.         UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)  
  103.         UIView.setAnimationDuration(NSTimeInterval(aniTime))  
  104.         UIView.setAnimationTransition(UIViewAnimationTransition.CurlUp, forView: view, cache: false)  
  105.         UIView.commitAnimations()  
  106.     }  
  107.       
  108.     func viewCurdown(view:UIView!,aniTime:Float!){  
  109.         UIView.beginAnimations(nil, context: nil)  
  110.         UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)  
  111.         UIView.setAnimationDuration(NSTimeInterval(aniTime))  
  112.         UIView.setAnimationTransition(UIViewAnimationTransition.CurlDown, forView: view, cache: false)  
  113.         UIView.commitAnimations()  
  114.     }  
  115.       
  116.     func viewPushUp(view:UIView!,aniTime:Float!,animoteKey:String!){  
  117.         var animation:CATransition = CATransition()  
  118.         animation.duration = CFTimeInterval(aniTime)  
  119.         animation.type = "push"  
  120.         animation.timingFunction = CAMediaTimingFunction(name: "easeOut")  
  121.         animation.fillMode = "forwards"  
  122.         animation.subtype = "fromTop"  
  123.         view.layer.addAnimation(animation, forKey: animoteKey)  
  124.     }  
  125.       
  126.     func viewPushDown(view:UIView!,aniTime:Float!,animoteKey:String!){  
  127.         var animation:CATransition = CATransition()  
  128.         animation.duration = CFTimeInterval(aniTime)  
  129.         animation.type = "push"  
  130.         animation.timingFunction = CAMediaTimingFunction(name: "easeOut")  
  131.         animation.fillMode = "forwards"  
  132.         animation.subtype = "fromBottom"  
  133.         view.layer.addAnimation(animation, forKey: animoteKey)  
  134.     }  
  135.       
  136.     func viewPushLeft(view:UIView!,aniTime:Float!,animoteKey:String!){  
  137.         var animation:CATransition = CATransition()  
  138.         animation.duration = CFTimeInterval(aniTime)  
  139.         animation.type = "push"  
  140.         animation.timingFunction = CAMediaTimingFunction(name: "easeOut")  
  141.         animation.fillMode = "forwards"  
  142.         animation.subtype = "fromLeft"  
  143.         view.layer.addAnimation(animation, forKey: animoteKey)  
  144.     }  
  145.       
  146.     func viewPushRight(view:UIView!,aniTime:Float!,animoteKey:String!){  
  147.         var animation:CATransition = CATransition()  
  148.         animation.duration = CFTimeInterval(aniTime)  
  149.         animation.type = "push"  
  150.         animation.timingFunction = CAMediaTimingFunction(name: "easeOut")  
  151.         animation.fillMode = "forwards"  
  152.         animation.subtype = "fromRight"  
  153.         view.layer.addAnimation(animation, forKey: animoteKey)  
  154.     }  
  155.       
  156.     func animationRotateAndScaleEffects(view:UIView!,aniTime:Float!){  
  157.         UIView.animateWithDuration(NSTimeInterval(aniTime), animations: {  
  158.             view.transform = CGAffineTransformMakeScale(0.001,0.001)  
  159.             var animation:CABasicAnimation = CABasicAnimation(keyPath: "transform")  
  160.               
  161.             animation.toValue = NSValue(CATransform3D: CATransform3DMakeRotation(CGFloat(M_PI), 1,0,0))  
  162.             animation.duration = CFTimeInterval(aniTime)  
  163.             }, completion: {completion in  
  164.                         UIView.animateWithDuration(NSTimeInterval(aniTime), animations: {  
  165.                            view.transform = CGAffineTransformMakeScale(1,1)  
  166.                     })  
  167.             })  
  168.     }  
  169.       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值