你的位置:首页 > 软件开发 > 操作系统 > iOS开发 - View Controller 的paging

iOS开发 - View Controller 的paging

发布时间:2016-04-17 18:00:05
在学习开源中国ios 源码时,发现其实现view controllers 的paging的方法如下:第一、定义一个容器类的view controller,类似于UIPageViewController. 该vc的主要由两部分组成: a 一个title view,用来表明当前 ...

在学习开源中国ios 源码时,发现其实现view controllers 的paging的方法如下:

第一、定义一个容器类的view controller,类似于UIPageViewController. 该vc的主要由两部分组成:

  a 一个title view,用来表明当前内容是什么,并且能够相应用户的点击,切换content

  b 一个table view controller (通过addChildViewController添加,并将table view controller 的view 添加到容器的view中),用来显示内容, 即响应用户的手势实现paging. 

第二是设置tableview的transform,将tableview旋转90度,设置pagingEnable为yes(UIScrollView的属性),并在table view delegate方法将cell的height设置为屏幕的宽度,这样就能够将table view变成一个能够paging的view了。

那么如何将view controllers的内容 添加到table view中去呢?首先将所有view controller添加到table view controller中去,然后将view controller的view 添加到table view cell 的content view中,这样table view cell中的内容就是view controllers 的内容了。

这种实现主要涉及三个角色:

1. 容器类的view controller, 主要用来协调title view 和table view controller

2. table view controller, 用来实现内容水平方向的paging

3. view controllers,用来提供内容

 

因为UIKit本身就提供了paging view controller,不知道为什么不直接用?

经过测试,可以使用paging view controller实现以上基本功能

代码:https://github.com/beddup/BeddupPageViewControllerDemo

 


原标题:iOS开发 - View Controller 的paging

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。