如何让动画在两个UIViews之间翻转

时间:2015-05-10 16:15:40

标签: ios xcode swift animation uiview

我正在尝试创建一个IOS应用程序,并在按下某些按钮时翻转两个视图。我找到了翻转动画,但是我希望翻转在翻转90°时将内容更改为新视图,而不是在动画完成时。这是我的功能:

func animationFlip(fromView:UIView, toView:UIView, animationTime:Float)
{

    UIView.animateWithDuration(NSTimeInterval(animationTime), animations: {

        UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromRight, forView: fromView, cache: true)

        },completion:{completion in
            UIView.animateWithDuration(NSTimeInterval(animationTime), animations: { () -> Void in

                fromView.hidden = true;
                toView.hidden = false;
                UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromRight, forView: toView, cache: true)


            })
    })
}

我发现这个代码似乎可以解决问题,但它是用obj-c编写的。如何将其翻译成快速的?

[UIView transitionFromView:viewToReplace
        toView:replacementView
        duration:1
        options:UIViewAnimationOptionTransitionFlipFromBottom
        completion:nil];

提前致谢!

1 个答案:

答案 0 :(得分:2)

在斯威夫特: -

UIView.transitionFromView(viewToReplace, toView: replacementView, duration: 1, options: .TransitionFlipFromBottom, completion: { _ in })