自定义 ViewController 像 UIPageViewController 那样的过渡
Custom ViewController Transition like UIPageViewController
如果您选择滚动样式,我想使用像 PageViewController 中那样的动画来导航真正的 ViewController。所以我想使用 left/right 滑动来导航它们。
没有 UIPageViewController 怎么办。
有没有办法开发可重用的 class 可以用作我的应用程序中的主要过渡样式?
感谢任何帮助
如果你想要和UIPageViewController
一样的效果,你应该直接使用它。这就是它的用途。如果您有真正的理由不使用它,那么您可以 google 实现容器视图控制器的许多教程中的任何一个。
好吧,我设法使用自定义故事板 Segues 做到了
这是代码:
自定义转场:
import UIKit
class CustomScrollPagingSegue: UIStoryboardSegue {
override func perform() {
let firstVCView = self.sourceViewController.view as UIView!
let secondVCView = self.destinationViewController.view as UIView!
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)
UIView.animateWithDuration(0.5, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)
}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as UIViewController, animated: false, completion: nil)
}
}
}
和自定义展开转场
import UIKit
class CustomScrollPagingSegueUnwind: UIStoryboardSegue {
override func perform() {
// Assign the source and destination views to local variables.
let secondVCView = self.sourceViewController.view as UIView!
let firstVCView = self.destinationViewController.view as UIView!
let screenWidth = UIScreen.mainScreen().bounds.size.width
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(firstVCView, aboveSubview: secondVCView)
// Animate the transition.
UIView.animateWithDuration(0.5, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, screenWidth, 0.0)
}) { (Finished) -> Void in
self.sourceViewController.dismissViewControllerAnimated(false, completion: nil)
}
}
}
我认为使用交互式过渡可以得到 100% 相同的结果,但我不知道如何实现它们。
如果您选择滚动样式,我想使用像 PageViewController 中那样的动画来导航真正的 ViewController。所以我想使用 left/right 滑动来导航它们。 没有 UIPageViewController 怎么办。 有没有办法开发可重用的 class 可以用作我的应用程序中的主要过渡样式?
感谢任何帮助
如果你想要和UIPageViewController
一样的效果,你应该直接使用它。这就是它的用途。如果您有真正的理由不使用它,那么您可以 google 实现容器视图控制器的许多教程中的任何一个。
好吧,我设法使用自定义故事板 Segues 做到了 这是代码:
自定义转场:
import UIKit
class CustomScrollPagingSegue: UIStoryboardSegue {
override func perform() {
let firstVCView = self.sourceViewController.view as UIView!
let secondVCView = self.destinationViewController.view as UIView!
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)
UIView.animateWithDuration(0.5, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)
}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as UIViewController, animated: false, completion: nil)
}
}
}
和自定义展开转场
import UIKit
class CustomScrollPagingSegueUnwind: UIStoryboardSegue {
override func perform() {
// Assign the source and destination views to local variables.
let secondVCView = self.sourceViewController.view as UIView!
let firstVCView = self.destinationViewController.view as UIView!
let screenWidth = UIScreen.mainScreen().bounds.size.width
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(firstVCView, aboveSubview: secondVCView)
// Animate the transition.
UIView.animateWithDuration(0.5, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, screenWidth, 0.0)
}) { (Finished) -> Void in
self.sourceViewController.dismissViewControllerAnimated(false, completion: nil)
}
}
}
我认为使用交互式过渡可以得到 100% 相同的结果,但我不知道如何实现它们。