我一直在关注如何实现自定义转场的教程。使用滑动手势 - 我滑动我的手指,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/