UIPageViewController跳跃切换的问题
2015-12-25 10:48
549 查看
使用的是XHScrollMenu和UIPageViewController来构建5个页面: ViewController1, ViewController2, ViewController3, ViewController4, ViewController5。 XHScrollMenu和UIPageViewController左右滑动均可以控制页面的切换。 一般情况下是正确的。 但如果点击了menu,切换ViewController1,然后再点击menu直接切换至ViewController5。 从ViewController5向右滑动往回切换的时候发现始终会直接切换至ViewController1,而不是ViewController4。 我用一个int变量来标识当前的页面,以此作为跳转的依据,但不起作用,原因是UIPageViewController调用Delegate的时候自动使用了ViewController1。 这可能是UIPageViewController的Bug,或者是一种缓存机制。 它的特点如下: 1. self . pageViewController = [[ UIPageViewController alloc ] initWithTransitionStyle : UIPageViewControllerTransitionStyleScroll navigationOrientation :UIPageViewControllerNavigationOrientationHorizontal options : nil ]; 2.使用menu来控制切换的代码如下 - ( void)scrollMenuDidSelected:( XHScrollMenu *)scrollMenu menuIndex:( NSUInteger)selectIndex { [_ pageViewController setViewControllers :[ NSArray arrayWithObject :[self viewControllerAtIndex :selectIndex]] direction :UIPageViewControllerNavigationDirectionForward animated : YES completion : NULL ] } 最后修改: - ( void)scrollMenuDidSelected:( XHScrollMenu *)scrollMenu menuIndex:( NSUInteger)selectIndex { if (selectIndex > _pageIndex) { //前翻或者后翻的条件判断 __block XX ViewController *blocksafeSelf = self; [ self . pageViewController setViewControllers :[ NSArray arrayWithObject :[ self viewControllerAtIndex :selectIndex]] direction :UIPageViewControllerNavigationDirectionForward animated : YES completion :^( BOOL finished) { if (finished) { dispatch_async( dispatch_get_main_queue(), ^{ [blocksafeSelf. pageViewController setViewControllers :[ NSArray arrayWithObject :[blocksafeSelf viewControllerAtIndex :selectIndex]] direction :UIPageViewControllerNavigationDirectionForward animated : NO completion : NULL ]; // bug fix for uipageview controller }); } }]; } else { __block RCOnlineViewController *blocksafeSelf = self; [ self . pageViewController setViewControllers :[ NSArray arrayWithObject :[ self viewControllerAtIndex :selectIndex]] direction :UIPageViewControllerNavigationDirectionReverse animated : YES completion :^( BOOL finished){ if (finished) { dispatch_async( dispatch_get_main_queue(), ^{ [blocksafeSelf. pageViewController setViewControllers :[ NSArray arrayWithObject :[blocksafeSelf viewControllerAtIndex :selectIndex]] direction :UIPageViewControllerNavigationDirectionReverse animated : NO completion : NULL ]; // bug fix for uipageview controller }); } }]; } }
相关文章推荐
- ConcurrentLinkedQueue学习记
- CSS3 Media Queries 实现网页自适应
- Android Stduio统计项目的代码行数
- 横向滚动的UITableView
- Jmeter参数化之Unique方式(LoadRunner有的JMeter也要有)测试圈:217937505 欢迎加入!!!
- JS解析查询字符串 parseQueryString
- UIView的一些基本方法 init、loadView、viewDidLoad、viewDidUnload、dealloc
- 设计模式之建造者模式(Builder)
- 更改UISearchBar 的背景色、取消按钮颜色
- Java并发库(十九):同步集合类的使用BlockingQueue、
- failed to find Build Tools revision 23.0.2
- Android UI视图效果篇之仿QQ好友列表分组悬浮PinnedHeaderExpandableListView
- String ,StringBuffer,StringBuilder精髓比較
- iOS系统UITextField研究
- Android设计模式之建造者模式(builder pattern)
- MySQL5.6添加root用户报错:Field 'ssl cipher' doesn't have a default value
- UIViewController的生命周期及iOS程序执行顺序
- Android 异步开发之 AsyncQueryHandler
- 常用的GitHub UI框架
- iOS流布局UICollectionView系列四——自定义FlowLayout进行瀑布流布局