UIPageViewController跳跃切换的问题

使用的是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

});

}

}];

}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值