快速

时间:2016-04-05 22:47:04

标签: ios git animation swift2 viewcontroller

我正试图在像这样的视图控制器中获得3d翻转动画

    https://github.com/nicklockwood/CubeController

对于动画..基于反向值我设置时钟方向或反时钟方向

这是我用于动画的代码..

    class CusNavAnimController : NSObject, UIViewControllerAnimatedTransitioning {

var reverse: Bool = false

func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {

    return 0.25
}

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {

    let containerView = transitionContext.containerView()

    let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!

    let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)!

    let toView = toViewController.view

    let fromView = fromViewController.view

    //
    toView.frame = UIScreen.mainScreen().bounds
    fromView.frame = UIScreen.mainScreen().bounds

    let direction: CGFloat = reverse ? -1 : 1
    let const: CGFloat = -0.005

    toView.layer.anchorPoint = CGPointMake(direction == 1 ? 0 : 1, 0.5)
    fromView.layer.anchorPoint = CGPointMake(direction == 1 ? 1 : 0, 0.5)

    var viewFromTransform: CATransform3D = CATransform3DMakeRotation(direction * CGFloat(M_PI_2), 0.0, 1.0, 0.0)
    var viewToTransform: CATransform3D = CATransform3DMakeRotation(-direction * CGFloat(M_PI_2), 0.0, 1.0, 0.0)

    viewFromTransform.m34 = const
    viewToTransform.m34 = const

    containerView!.transform = CGAffineTransformMakeTranslation(direction * containerView!.frame.size.width / 2.0, 0)
    toView.layer.transform = viewToTransform

    containerView!.addSubview(toView)

    UIView.animateWithDuration(transitionDuration(transitionContext), animations: {

        containerView!.transform = CGAffineTransformMakeTranslation(-direction * containerView!.frame.size.width / 2.0, 0)
        fromView.layer.transform = viewFromTransform
        toView.layer.transform = CATransform3DIdentity

        }, completion: {

            finished in

            containerView!.transform = CGAffineTransformIdentity
            fromView.layer.transform = CATransform3DIdentity
            toView.layer.transform = CATransform3DIdentity
            fromView.layer.anchorPoint = CGPointMake(0.5, 0.5)
            toView.layer.anchorPoint = CGPointMake(0.5, 0.5)

            if (transitionContext.transitionWasCancelled()) {

                toView.removeFromSuperview()

            } else {

                fromView.removeFromSuperview()
            }

            transitionContext.completeTransition(!transitionContext.transitionWasCancelled())
    })
}}

我正在获取动画,但它与提供的git hub链接不同。 对于我的代码.. fromview稍微回过头来看看从那一点来到前面..任何人都可以建议我改变

1 个答案:

答案 0 :(得分:0)

UIViewAnimationOptions

中查看TransitionFlipFromLeftTransitionFlipFromRight