这段代码可以成功地实现自定义segue向下动画过渡。如何使动画看起来像向左或向右过渡呢?
此外,我正在使用UISwipeGestureRecognizer触发segue。它能正常工作,但只要我做出最小的滑动,segue就会发生。如何让segue在用户松开手指或至少进行更大的滑动之后才发生?我需要使用scrollView吗?
以下是我的UISwipeGestureRecognizer代码。
下面的代码是我的动画代码。
此外,我正在使用UISwipeGestureRecognizer触发segue。它能正常工作,但只要我做出最小的滑动,segue就会发生。如何让segue在用户松开手指或至少进行更大的滑动之后才发生?我需要使用scrollView吗?
以下是我的UISwipeGestureRecognizer代码。
override func viewDidLoad() {
var swipeGestureRecognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "showSecondViewController")
swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirection.Up
self.view.addGestureRecognizer(swipeGestureRecognizer)
}
下面的代码是我的动画代码。
class FirstCustomSegue: UIStoryboardSegue {
override func perform() {
// 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.5, 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)
}
}
}