I would like to change my animation between the view. Currently i have the PageCurl but i would like to have a Scroll animation like Snapchat.
我想在视图之间改变我的动画。目前我有PageCurl,但我想要一个像Snapchat这样的滚动动画。
I can not use the var transitionStyle: UIPageViewControllerTransitionStyle { get }
我不能使用var transitionStyle: UIPageViewControllerTransitionStyle {get}
My ViewController :
我的ViewController:
import UIKit
class ViewController: UIPageViewController, UIPageViewControllerDataSource{
let pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
var messagesViewController : MessagesViewController!
var searchViewController : SearchViewController!
var friendsViewController : FriendsViewController!
override func viewDidLoad() {
super.viewDidLoad()
// set UIPageViewControllerDataSource
self.dataSource = self
// Reference all of the view controllers on the storyboard
self.messagesViewController = self.storyboard?.instantiateViewControllerWithIdentifier("messagesViewController") as? MessagesViewController
self.messagesViewController.title = "Messages"
self.searchViewController = self.storyboard?.instantiateViewControllerWithIdentifier("searchViewController") as? SearchViewController
self.searchViewController.title = "Search"
self.friendsViewController = self.storyboard?.instantiateViewControllerWithIdentifier("friendsViewController") as? FriendsViewController
self.friendsViewController.title = "Friends"
// Set starting view controllers
var startingViewControllers : NSArray = [self.searchViewController]
self.setViewControllers(startingViewControllers, direction: .Forward, animated: false, completion: nil)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
switch viewController.title! {
case "Messages":
return nil
case "Search":
return messagesViewController
case "Friends":
return searchViewController
default:
return nil
}
}
// pink green blue
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
switch viewController.title! {
case "Messages":
return searchViewController
case "Search":
return friendsViewController
case "Friends":
return nil
default:
return nil
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
2 个解决方案
#1
10
From the Apple Docs:
从苹果的文档:
"The value of this property is set when the page view controller is initialized, and cannot be changed."
“该属性的值是在页面视图控制器初始化时设置的,不能更改。”
You must specify the transition style when you initialize. If you do that in code, you will need something like:
您必须在初始化时指定转换样式。如果您在代码中这样做,您将需要以下内容:
let pageViewController = ViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
(Since ViewController
is a subclass of UIPageViewController
)
(因为ViewController是UIPageViewController的子类)
If you are setting up the Page View Controller in a storyboard, amend the transition style in the attributes inspector:
如果您在故事板中设置页面视图控制器,请修改属性检查器中的过渡样式:
#2
2
If you need to use storyboard and still need to set the transition style in code you can use this trick in the Class you made inheriting UIPageViewController. The trick is that in the init with coder you call super.init() which takes transition style like this
如果你需要使用storyboard并且仍然需要在代码中设置转换样式,你可以在继承UIPageViewController的类中使用这个技巧。诀窍在于,在initwithcoder中调用super.init(),它采用如下的转换样式
class ViewController: UIPageViewController {
required init?(coder: NSCoder) {
super.init(transitionStyle: Configs.transitionStyle, navigationOrientation: .horizontal, options: nil)
}
}
#1
10
From the Apple Docs:
从苹果的文档:
"The value of this property is set when the page view controller is initialized, and cannot be changed."
“该属性的值是在页面视图控制器初始化时设置的,不能更改。”
You must specify the transition style when you initialize. If you do that in code, you will need something like:
您必须在初始化时指定转换样式。如果您在代码中这样做,您将需要以下内容:
let pageViewController = ViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
(Since ViewController
is a subclass of UIPageViewController
)
(因为ViewController是UIPageViewController的子类)
If you are setting up the Page View Controller in a storyboard, amend the transition style in the attributes inspector:
如果您在故事板中设置页面视图控制器,请修改属性检查器中的过渡样式:
#2
2
If you need to use storyboard and still need to set the transition style in code you can use this trick in the Class you made inheriting UIPageViewController. The trick is that in the init with coder you call super.init() which takes transition style like this
如果你需要使用storyboard并且仍然需要在代码中设置转换样式,你可以在继承UIPageViewController的类中使用这个技巧。诀窍在于,在initwithcoder中调用super.init(),它采用如下的转换样式
class ViewController: UIPageViewController {
required init?(coder: NSCoder) {
super.init(transitionStyle: Configs.transitionStyle, navigationOrientation: .horizontal, options: nil)
}
}