【发布时间】:2017-09-25 14:57:16
【问题描述】:
我想要做的是使用 Swift 3 以编程方式呈现一个新的视图控制器,并根据用户输入的视图控制器进行动画淡出然后淡入和弹出然后弹出。这让我的应用感觉更现代,不那么陈旧和块状。
这是我用于呈现新视图控制器的当前方法。它有效,但它相当突然和机器人:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let ExampleVC = storyBoard.instantiateViewController(withIdentifier: "ExampleVC")
//ExampleVC standing for ExampleViewController
self.navigationController?.pushViewController(ExampleVC, animated: false)
这里有一种动画 UIViews 的方法,但它不适用于 UIViewControllers
func popIn(yourView : UIView) {
yourView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
UIView.animateKeyframes(withDuration: 0.2, delay: 0.0, options: UIViewKeyframeAnimationOptions.calculationModeDiscrete, animations: {
yourView.transform = .identity
}, completion: nil)
self.view.addSubview(yourView)
}
我需要类似的东西,但对于 UIViewController
更新
这是您用来以一种很酷的方式呈现新的视图控制器以使您的应用更现代的方法
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let VC = storyboard.instantiateViewController(withIdentifier: "Example") //<<< make sure you enter in your storyboard ID here or you will crash your app
VC.modalTransitionStyle = .crossDissolve //you can change this to do different animations
VC.view.layer.speed = 0.1 //adjust this to animate at different speeds
self.navigationController?.present(VC, animated: true, completion: nil)
如果你有任何问题可以评论他们,我可以帮助你们解决问题
【问题讨论】:
标签: ios swift animation uiviewcontroller