gpt4 book ai didi

ios - 以编程方式呈现新的 ViewController [Swift 3]

转载 作者:搜寻专家 更新时间:2023-11-01 06:31:44 24 4
gpt4 key购买 nike

我想做的是使用 Swift 3 以编程方式呈现一个新的 View Controller ,其中包含动画淡出然后淡入以及弹出窗口然后弹出窗口,具体取决于用户输入的 View Controller 。这样我的应用程序感觉更现代,不那么陈旧和 block 状。

这是我当前用于呈现新 View Controller 的方法。它有效,但它相当生硬和机械化:

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

更新

这里是您可以用来以一种很酷的方式呈现新的 View Controller 以使您的应用程序更现代

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)

如果你有任何问题,请发表评论,我可以帮助你们解决问题

最佳答案

var storyboard = UIStoryboard(name: "Main", bundle: nil)
var ivc = storyboard.instantiateViewController(withIdentifier: "ExampleVC")
ivc.modalTransitionStyle = .crossDissolve
ivc.view.layer.speed = 0.1
self.present(ivc, animated: true, completion: { _ in })

检查此动画代码以查看 Controller

关于ios - 以编程方式呈现新的 ViewController [Swift 3],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46408300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com