使用UIPageViewController将PageCurl转换为Scroll

Pix*_*xel 5 ios uipageviewcontroller swift xcode6 swift-playground

我想在视图之间更改动画.目前我有PageCurl但我希望有一个像Snapchat这样的Scroll动画.

我不能用 var transitionStyle: UIPageViewControllerTransitionStyle { get }

在此输入图像描述

我的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.
    }

}
Run Code Online (Sandbox Code Playgroud)

pba*_*sdf 10

来自Apple Docs:

"初始化页面视图控制器时,将设置此属性的值,并且无法更改."

初始化时必须指定过渡样式.如果您在代码中执行此操作,则需要以下内容:

let pageViewController = ViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
Run Code Online (Sandbox Code Playgroud)

(因为ViewController是子类UIPageViewController)

如果要在故事板中设置页面视图控制器,请在属性检查器中修改过渡样式:

属性检查员的图像

  • `UIPageViewController`只有两种过渡样式:`Scroll`或`PageCurl`.`FlipHorizo​​ntal`是一个`UIModalTransitionStyle`,用于以模态方式呈现视图控制器.如果你想要FlipHorizo​​ntal或类似的东西,你将需要使用UIPageViewController以外的东西. (2认同)