ios - UIStoryboardSegue : view is not displayed during animation

标签 ios xcode swift segue unwind-segue

当我的自定义 segue 动画正在执行时,目标 View 显示为黑色。动画结束后出现 View ,看起来不错。

截图如下:

动画场景:

转场/动画完成后的 View :

这是自定义转场类:

class SegueToPreview: UIStoryboardSegue {

override func perform() {
    // Assign the source and destination views to local variables.
    var firstVCView = self.sourceViewController.view as UIView!
    var secondVCView = self.destinationViewController.view as UIView!

    // Get the screen width and height.
    let screenWidth = UIScreen.mainScreen().bounds.size.width
    let screenHeight = UIScreen.mainScreen().bounds.size.height

    // Specify the initial position of the destination view.
    secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)

    // Access the app's key window and insert the destination view above the current (source) one.
    let window = UIApplication.sharedApplication().keyWindow
    window?.insertSubview(secondVCView, aboveSubview: firstVCView)

    // Animate the transition.
    UIView.animateWithDuration(0.2, animations: { () -> Void in

        firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0)
        secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)

        }) { (Finished) -> Void in
            self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
                animated: false,
                completion: nil)
    }

}

虽然 unwind segue 工作正常,显示两个 View 。

我假设在执行动画时未加载 View ,但不知道如何解决。

最佳答案

目标 vc View 的初始位置设置不正确(假设您希望 View 从右侧移入);你把它放在屏幕下方,而不是屏幕右侧,

secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)

这应该是,

secondVCView.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight)

关于ios - UIStoryboardSegue : view is not displayed during animation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30715082/

相关文章:

ios - 在 UIView 子类中声明的委托(delegate)在 UIViewController 中不起作用?

ios - 不使用目标的可选项目资源

ios - 如何用swift拍照并保存到app本地

Swift 3 脚本 - 访问进程参数

ios 7 datePicker 项目上有不需要的白色背景,可能是错误

ios - 为什么编译器在使用 Swift 的 Xcode 6 beta 3 中提示?

ios - - (id) 来自 Swift 中的 Obj-C Lib?

ios - 将来自麦克风的音频录制为 .wav 格式并使用 Xamarin.ios 中的 AudioUnit 进行播放

ios - Swift - 如何在 UIStackview 上设置点击事件

swift - 将表中的自定义accessoryView更改为Swift 3中的不同accessoryView