如何在Swift中调用UIViewController的transitionFromViewController?

时间:2014-07-04 09:23:27

标签: uiviewcontroller swift

我应该如何使用Swift实现此方法调用?

[containerViewController transitionFromViewController:fromViewController
                                         toViewController:toViewController
                                                 duration:0.2
                                                  options:UIViewAnimationOptionTransitionCrossDissolve
                                               animations:nil
                                               completion:^(BOOL finished) {
                                                   [fromViewController removeFromParentViewController];
                                                   [toViewController didMoveToParentViewController:containerViewController];
                                                   toViewController.view.frame = containerViewController.view.bounds;
                                               }];

====

    containerViewController.transitionFromViewController(
        fromViewController,
        toViewController,
        0.2,
        UIViewAnimationOptionTransitionCrossDissolve,
        nil,
        nil)

我收到此错误:使用未解析的标识符'UIViewAnimationOptionTransitionCrossDissolve'

3 个答案:

答案 0 :(得分:8)

工作解决方案:

containerViewController.transitionFromViewController(
            fromViewController,
            toViewController: toViewController,
            duration: 0.2,
            options: UIViewAnimationOptions.TransitionCrossDissolve,
            nil,
            completion: { finished in
                fromViewController.removeFromParentViewController()
                toViewController.didMoveToParentViewController(containerViewController)
                toViewController.view.frame = containerViewController.view.bounds
            })

答案 1 :(得分:2)

.TransitionCrossDissolve代替UIViewAnimationOptionTransitionCrossDissolve。类型UIViewAnimationOption是已知的方法,可以推断出来。

答案 2 :(得分:0)

斯威夫特3:

containerViewController.transition(from: fromViewController,
                                   to: toViewController,
                                   duration: 0.2,
                                   options: .transitionCrossDissolve,
                                   nil,
                                   completion: { _ in
                                    fromViewController.removeFromParentViewController()
                                    toViewController.didMove(toParentViewController: containerViewController)
                                    toViewController.view.frame = containerViewController.view.bounds
})