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

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

import Foundation
import UIkit
import QuartzCore

class Animator{
     func flipHorizontalViewContorller(nextController: UIViewController!,selfViewController: UIViewController!,back:() -> Void){
        nextController.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal
        selfViewController.presentViewController(nextController, animated: true, completion:back)
    }
    
    func coverVerticalViewContorller(nextController: UIViewController!,selfViewController: UIViewController!,back:() -> Void){
        nextController.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
        selfViewController.presentViewController(nextController, animated: true, completion:back)
    }
    
    func crossDissolveViewContorller(nextController: UIViewController!,selfViewController: UIViewController!,back:() -> Void){
        nextController.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
        selfViewController.presentViewController(nextController, animated: true, completion:back)
    }
    
    func partialCurlViewContorller(nextController: UIViewController!,selfViewController: UIViewController!,back:() -> Void){
        nextController.modalTransitionStyle = UIModalTransitionStyle.PartialCurl
        selfViewController.presentViewController(nextController, animated: true, completion:back)
    }
    
    func viewMoveInFromLeft(nextView:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "moveIn"
        animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")
        animation.subtype = "fromLeft"
        animation.fillMode = "forwards"
        nextView.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewMoveInFromRight(nextView:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "moveIn"
        animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")
        animation.subtype = "fromRight"
        animation.fillMode = "forwards"
        nextView.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewMoveInFromTop(nextView:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "moveIn"
        animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")
        animation.subtype = "fromTop"
        animation.fillMode = "forwards"
        nextView.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewMoveInFromBottom(nextView:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "moveIn"
        animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")
        animation.subtype = "fromBottom"
        animation.fillMode = "forwards"
        nextView.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewFadeOut(nextView:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "fade"
        animation.timingFunction = CAMediaTimingFunction(name: "easeOut")
        animation.fillMode = "forwards"
        nextView.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewFadeIn(nextView:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "fade"
        animation.timingFunction = CAMediaTimingFunction(name: "easeIn")
        animation.fillMode = "forwards"
        nextView.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewFlipFromLeft(view:UIView!,aniTime:Float!){
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(NSTimeInterval(aniTime))
        UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromLeft, forView: view, cache: false)
        UIView.commitAnimations()
    }
    
    func viewFlipFromRight(view:UIView!,aniTime:Float!){
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(NSTimeInterval(aniTime))
        UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromRight, forView: view, cache: false)
        UIView.commitAnimations()
    }
    
    func viewCurup(view:UIView!,aniTime:Float!){
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(NSTimeInterval(aniTime))
        UIView.setAnimationTransition(UIViewAnimationTransition.CurlUp, forView: view, cache: false)
        UIView.commitAnimations()
    }
    
    func viewCurdown(view:UIView!,aniTime:Float!){
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(NSTimeInterval(aniTime))
        UIView.setAnimationTransition(UIViewAnimationTransition.CurlDown, forView: view, cache: false)
        UIView.commitAnimations()
    }
    
    func viewPushUp(view:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "push"
        animation.timingFunction = CAMediaTimingFunction(name: "easeOut")
        animation.fillMode = "forwards"
        animation.subtype = "fromTop"
        view.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewPushDown(view:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "push"
        animation.timingFunction = CAMediaTimingFunction(name: "easeOut")
        animation.fillMode = "forwards"
        animation.subtype = "fromBottom"
        view.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewPushLeft(view:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "push"
        animation.timingFunction = CAMediaTimingFunction(name: "easeOut")
        animation.fillMode = "forwards"
        animation.subtype = "fromLeft"
        view.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func viewPushRight(view:UIView!,aniTime:Float!,animoteKey:String!){
        var animation:CATransition = CATransition()
        animation.duration = CFTimeInterval(aniTime)
        animation.type = "push"
        animation.timingFunction = CAMediaTimingFunction(name: "easeOut")
        animation.fillMode = "forwards"
        animation.subtype = "fromRight"
        view.layer.addAnimation(animation, forKey: animoteKey)
    }
    
    func animationRotateAndScaleEffects(view:UIView!,aniTime:Float!){
        UIView.animateWithDuration(NSTimeInterval(aniTime), animations: {
            view.transform = CGAffineTransformMakeScale(0.001,0.001)
            var animation:CABasicAnimation = CABasicAnimation(keyPath: "transform")
            
            animation.toValue = NSValue(CATransform3D: CATransform3DMakeRotation(CGFloat(M_PI), 1,0,0))
            animation.duration = CFTimeInterval(aniTime)
            }, completion: {completion in
                        UIView.animateWithDuration(NSTimeInterval(aniTime), animations: {
                           view.transform = CGAffineTransformMakeScale(1,1)
                    })
            })
    }
    
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值