ios - Segue 动画/故障和延长滑动手势长度上的黑屏

标签 ios swift segue swipe

我一直在关注如何实现自定义转场的教程。使用滑动手势 - 我滑动我的手指,segue 工作但不是平滑过渡,第二个 ViewController 向上/向下滑动以替换当前的,我得到一个黑屏然后目标 ViewController 加载..

这在前进和倒带转场中都会发生。

我附上了正常转场(不是倒带)的动画代码。

此外,当我轻轻滑动屏幕时,segue 会立即发生。我将如何做到这一点,以便在我的手指松开(或者在模拟器的情况下,单击鼠标)之前不会发生 segue。我必须使用 scrollViews 吗?或者仅使用 swipeGestureRecognizers 和自定义 segues 就可以实现这种效果。

谢谢!

class FirstCustomSegue: UIStoryboardSegue {

override func perform() {

    // Animate the transition.
    UIView.animateWithDuration(0.4, animations: { () -> Void in
        firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
        secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)

        }) { (Finished) -> Void in

            // Animate the transition.
            UIView.animateWithDuration(0.4, animations: { () -> Void in
                firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
                secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)

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

}

最佳答案

试试这段代码,我更改了 self.destinationViewController... 的最后一行

class FirstCustomSegue: UIStoryboardSegue {

    override func perform() {

        // Animate the transition.
        UIView.animateWithDuration(0.4, animations: { () -> Void in
            firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
            secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)

            }) { (Finished) -> Void in

                // Animate the transition.
                UIView.animateWithDuration(0.4, animations: { () -> Void in
                    firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
                    secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)

                    }) { (Finished) -> Void in
                        self.sourceViewController.presentViewController(self.storyboard.instantiateViewControllerWithIdentifier("YOUR_IDENTIFIER"),
                            animated: false,
                            completion: nil)
                }
        }
    }

}

YOUR_IDENTIFIER 替换为与您的 View Controller 匹配的 Storyboard ID。

关于ios - Segue 动画/故障和延长滑动手势长度上的黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31379064/

相关文章:

ios - UIScrollview 拉动刷新不起作用

android - 自定义原生库的标签

arrays - Swift 3 - UIView 的二维数组

ios - 从第二个 View 在第一个 View 中的初始功能(快速)

ios - 检查Admob插屏是否完成

ios - 如何将 Youtube 视频嵌入到我的应用程序中?

iphone - 增加 FBLoginView 的框架大小

ios - Xcode 9 中的 Swift 4 - 读取核心数据中的数据失败

ios - 单独在 Swift 中创建自定义 sqlite 函数

ios - 在其他 UIPageViewController 中执行 segue