Swift如何从左到右做uiview幻灯片的外观

时间:2015-01-22 08:16:17

标签: xcode swift swipe slide

我设计了一些相互交互的UIView。但是当视图出现时总是从右向左滑动(默认)。 但我想在某些情况下左右显示(例如我向右滑动)。 我怎么不能从Swift代码中做到这一点?

更新

我找到了解决此问题的方法

            let slideInFromLeftTransition = CATransition()
            // Customize the animation's properties
            slideInFromLeftTransition.type = kCATransitionPush
            slideInFromLeftTransition.subtype = kCATransitionFromLeft
            slideInFromLeftTransition.duration = 0.5
            slideInFromLeftTransition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
            slideInFromLeftTransition.fillMode = kCAFillModeRemoved

            // Add the animation to the View's layer
            self.navigationController?.view.layer.addAnimation(slideInFromLeftTransition, forKey: "slideInFromLeftTransition")

这解决了。

1 个答案:

答案 0 :(得分:0)

快速4.2中的解决方案:

func transitionVc(vc: UIViewController, type: CATransitionSubtype) {
        let transition = CATransition()
        transition.duration = 0.3
        transition.type = CATransitionType(rawValue: "push")
        transition.subtype = type
        self.navigationController?.view.layer.add(transition, forKey: kCATransition)
        self.navigationController?.pushViewController(vc, animated: false)
    }

通过以下方式使用它们:

let viewController = YourViewController()

transitionVc(vc: viewController!, type: .fromLeft)

transitionVc(vc: viewController, type: .fromRight)