zoukankan      html  css  js  c++  java
  • iOS UIPageViewController

    ios5中就引入了这个 UIPageViewController,它也是一种controller容器,提供了2种在controller之间切换的动画,一种是很普通的滑动效果,另一种是很炫的书翻页效果。如果你的程序有多个在功能上并列的controller,并且适合使用以上2种动画进行切换,那么就应当使用UIPageViewController。

    关于UIPageViewController,有2个重要的属性,这2个属性都是在采用书翻页效果的动画时才有用的,一个是spineLocation,一个是doubleSided。其中spineLocation表示书脊的位置,有min,mid,max三个选项,其中,min为书脊居左或上,mid为居中,max为居右或下。doubleSided表示是否采用双面显示。

    建立一个UIPageViewController模板的最简单的方法是利用xcode的模板,如下图:

    UIPageViewController 的特点是,

    1.它不同于navigation controller,没有自己的stack来保存以前的controller,它的示例代码也是每次都创建新的controller。虽然可以使用其他方法恢复以前的状态,但是可以看出,UIPageViewController的目的是创建一些不需要保存状态的controller,更多是为了展示图片等内容用的,而不是另外一种navigation controller。

    2.它每次显示的controller的个数是1个或是2个,具体是1个还是2个,需要看使用的过渡动画和doubleSided,spineLocation属性。具体为:

    2.1 当使用UIPageViewControllerTransitionStyleScroll时,一次只能显示1个viewcontroller。

    2.2 当使用UIPageViewControllerTransitionStylePageCurl时,通过调用

    - (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;

    一次可以显示2个controller,如下表

    Spine location

    Double sided

    What to pass

    UIPageViewControllerSpineLocationMid

    YES

    Pass the page to be displayed on the left and the page to be displayed on the right.

    UIPageViewControllerSpineLocationMin orUIPageViewControllerSpineLocationMax

    YES

    Pass the front of the page to be displayed and the back of the previously-displayed page. The back is used for the page turning animation.

    UIPageViewControllerSpineLocationMin orUIPageViewControllerSpineLocationMax

    NO

    Pass the front of the page to be displayed.

     2.2.1 从表中可以看出,当spine的位置在中间时,doubleSieded必须设置为YES,原文是这样写的If the spine is located in the middle, the value must be YES. Setting it to NO with the spine located in the middle raises an exception.其实规定容易理解,因为如果采用了spine在中间,那么就有如下效果:

    这样的翻页,翻页的背面当然要有新一页的内容,这样才像生活中使用的书。背面的效果如下图:

    2.2.2 

    根据文档所说,当doubleSided是yes时,Spine location 不是mid时,也应该传2个controller给

    - (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;

    但是,我传入2个就会报错,不明白原因。上面的demo的效果如下:

    3.如果采用了书籍翻页效果,那么最好保持所有的controller实例都产生于同一个类,仅仅更改显示的信息,这样就能保证界面的统一,看起来更像书籍。

  • 相关阅读:
    单例模式
    Curator Zookeeper分布式锁
    LruCache算法原理及实现
    lombok 简化java代码注解
    Oracle客户端工具出现“Cannot access NLS data files or invalid environment specified”错误的解决办法
    解决mysql Table ‘xxx’ is marked as crashed and should be repaired的问题。
    Redis 3.0 Cluster集群配置
    分布式锁的三种实现方式
    maven发布项目到私服-snapshot快照库和release发布库的区别和作用及maven常用命令
    How to Use Convolutional Neural Networks for Time Series Classification
  • 原文地址:https://www.cnblogs.com/breezemist/p/3494515.html
Copyright © 2011-2022 走看看