关于Page翻页效果--Page View Controller

Page View Controllers
你使用一个page view controller用page by page的方式来展示内容。一个page view controller管理一个self-contained视图架构。这个架构的父视图由page View controller管理,并且子视图由你提供的view Controllers管理。

一,解析Page View Controller
一个page view controller有一个单独的视图,是你的内容的存放的地方。
下图显示了page view interface的结构:最外面的棕色视图是父视图控制器,不是page view controller自身。page view controller没有自己的UI;然而,它对它的children做一个翻页效果。

关于Page翻页效果--Page View Controller - supershll - 记忆里

 

二,page view controller interface的对象:
一个可选的代理,一个可选的数据源,一组current view controllers,一组手势识别者

关于Page翻页效果--Page View Controller - supershll - 记忆里

 

数据源按需提供viewControllers。
委托提供响应基于手势的导航和方向更改。
view Controllers的数组包含当前要显示的content view controller。数组中的items的数量基于传递给page view controller的选项。
手势识别者只有在数据源被指定时才存在。这些手势识别者使用户通过轻击、flicking(快速滑动)或拖动翻页。

三,创建page view controller interface:
page view controller的view可以被缩放和嵌入到一个视图层次架构中。这意味着,不像一个导航控制器或tab bar controller,page view controller可以在广阔的范围内使用,而不是一些特别的情况。

1,通过stroyboard创建page view controller: Page-Based Application Xcode模版创建一个新的带page view controller的工程。
要添加一个page view controller到一个已经存在的storyboard:
1)拖动一个page view controller,并添加一个page view controller scene 到你的storyboard.
2)在属性检查器中,设置适当的选项。
3)可选地,设置一个委托,数据源
4)。。。

2,通过代码创建一个page view controller:
1)通过initWithTransitionStyle:navigationOrientation:options:方法创建一个page view controller
2)可选地,设置一个代理、数据源
3)设置初始的content view controllers
4) 在屏幕上显示page view controller的view。

3,设置最初的view controller:无论你是通过代码创建还是通过IB创建了一个page view controller,你都需要在将其显示到屏幕之前指定一个初始的view controller。
调用setViewControllers:direction:animated:completion:方法。

如果page view controller没有initial view controller,它的shouldAutorotateToInterfaceOrientation:返回NO,并抛出一个异常。

四,自定义初始化行为:
在初始化时,你传递给initWithTransitionStyle:navigationOrientation:options:方法的参数值和选项来自定义一个page view controller。在初始化后,这些属性都是只读的。你可以自定义:
1)The direction in which navigation occurs.
2)The location of the spine.(书脊的位置)
3)The transition style. In iOS 5, the only valid transition style is UIPageViewControllerTransitionStylePageCurl.

例如,

Listing 3-1  Customizing a page view controller
NSDictionary * options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:UIPageViewControllerSpineLocationMid] forKey:UIPageViewControllerOptionSpineLocationKey];

UIPageViewController *pageViewController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];

五、在运行时使用代理自定义行为:
UIPageViewControllerDelegate协议:可以在设备方向更改时和用户导航到一个新页时执行动作,并且它可以更新书脊的位置来响应方向的转变。

六、通过数据源提供内容:
数据源的方法被当前显示的view controller调用,并返回它之前和之后的view controller。为了简化查找前面和后面的viewcontroller,你可以在你的view controller里存储额外的信息,例如一个page number。
如果指定了数据源,page view controller将关联手势识别到它的view。这些手势通过gestureRecognizers属性访问。

要移动手势识别到另一个view,传递gestureRecognizers属性的值给目标view的addGestureRecognizer:方法。

例如,如果你的page view controller没有充满屏幕,你将手势识别传递给其superview,可以更好地翻页,而不用必须在page view controller内翻页。

七,通过设置current view controller提供内容:
setViewControllers:direction:animated:completion:方法直接控制显示哪些内容。
如果你没有设置数据源,你需要提供UI来移动pages,例如前进和后退按钮。手势驱动的导航只有在在你提供了数据源的时候才可用。

八,特别考虑Right-to-Left和Bottom-to-Top Content:
要通过数据源,使用一个page view controller来显示一个right-to-left或bottom-to-top内容,只需要反转下面两个方法的实现:
1)在你的数据源中,实现pageViewController:viewControllerBeforeViewController: 并返回之后的的viewController
2)pageViewController:viewControllerAfterViewController:返回前面的viewController>

并且,你一般要设置书脊的位置为UIPageViewControllerSpineLocationMax

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值