【问题标题】:Black Screen on Segue Animation / Glitchy & Extend swipe gesture lengthSegue 动画上的黑屏/故障和延长滑动手势长度
【发布时间】:2015-07-13 08:51:49
【问题描述】:

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

这发生在前进和后退转场上。

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

此外,当我轻轻滑动屏幕时,segue 会立即发生。我将如何做到这一点,直到我的手指被抬起(或者在模拟器的情况下,鼠标点击)之前不会发生segue。我必须使用滚动视图吗?或者仅使用 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)
            }
       }
   }

}

【问题讨论】:

    标签: ios swift segue swipe


    【解决方案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。

    【讨论】:

    • 太棒了! - 非常感谢 - 我实际上刚刚删除了最后一个动画块。您知道如何使用 swipeGestureRecognizer 解决问题吗?一旦我进行最小的滑动,segue 就会发生。在我释放之前是否可以不启动 segue,或者我是否需要使用 scrollView 来获得这种预期的效果?
    猜你喜欢
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多