我想在动画完成时从我正在加载的 viewController 执行一个 segue 到下一个 viewController:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animateWithDuration(1.5, delay: 0.5, options: UIViewAnimationOptions.CurveLinear, animations: {
self.loggo_image.alpha = 1.0
self.performSegueWithIdentifier("LogInView", sender: nil)
}, completion: nil)
}
我知道代码本身可能是错误的,但它只是显示示例。由于我没有任何按钮或类似按钮来创建到 Storyboard 中下一个 View 的转场(CTRL 在 Storyboard 中单击),我想我需要以编程方式进行。虽然我不知道如何设置我想去的 View 的“标识符”。如示例所示,我尝试简单地使用自定义类名,这是不正确的。
那怎么办?是 Storyboard ID 吗?标题?
最佳答案
让我们来解决您的问题:
I want to perform a segue from my loading viewController to the next viewController when an animation is finished
当动画完成意味着代码错误时(你说“我知道代码本身可能是错误的”是对的),你应该在完成时执行你的segue
block ,如下:
UIView.animateWithDuration(1.5, delay: 0.5, options: UIViewAnimationOptions.CurveLinear, animations: {
self.loggo_image.alpha = 1.0
}, completion: { _ in
self.performSegueWithIdentifier("LogInView", sender: nil)
})
Though I can't work out how to set the "identifier" of the view I want to go to. As shown in the example, I tried simply using the custom class name, which isn't right.
So how? Is it Storyboard ID? Title?
我在 this answer 中详细描述了如何准确地实现这一目标.
另外:
如果您需要在不使用 segues 的情况下导航到另一个 viewController,请检查一下(在这种情况下您必须使用 Storyboard ID):
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
// "nextView" is Storyboard ID
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
// now you can choose between pushing:
self.navigationController?.pushViewController(nextViewController, animated: true)
// or presenting:
self.presentViewController(nextViewController, animated:true, completion:nil)
希望对您有所帮助。
关于ios - performSegue 动画完成,什么标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40127982/