ios - performSegue 动画完成,什么标识符?

标签 ios iphone swift uistoryboardsegue

我想在动画完成时从我正在加载的 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(nextViewContro‌​ller, animated: true)
// or presenting:
self.presentViewController(nextViewController, animated:true, completion:nil)

希望对您有所帮助。

关于ios - performSegue 动画完成,什么标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40127982/

相关文章:

ios - SpriteKit SKTexture 未作为对 SKSpriteNode 的引用传递

ios - 使用文件路径初始化 AG 地理数据库的对象返回“文件未找到

ios - 从 NSString 创建KeychainValue

ios - 排除 pod iOS 的特定资源

ios - 如何在 iOS 6 中将 Tab Bar 的背景颜色更改为半透明

iphone - 如果我从 (__bridge) 使用 CGImageSourceCreateWithData,是否需要 "CFRelease"?

iphone - 在我的 iPhone 应用程序项目中出现内存泄漏我应该如何解决它?

ios - 从子 CollectionViewCell 访问父 tableViewCell

c# - View 消失后 AVAudioRecorder 崩溃

ios - 如何将 "collapse"多个推送通知合并为一个?