Segue上的黑屏动画/ Glitchy&延长滑动手势长度

时间:2015-07-13 08:51:49

标签: ios swift segue swipe

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

这在前进和后退segue上都会发生。

我已经附加了正常segue的动画代码(不是倒带)。

另外,当我轻轻地滑动屏幕时,瞬间发生了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)
            }
       }
   }

}

1 个答案:

答案 0 :(得分:1)

尝试此代码,我更改了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替换为与您的视图控制器匹配的情节提要ID。