I am currently developing an iOS
project that is based in a Page View Controller
. Everything works fine, however, I would like to prevent the user to go beyond the limits of the pages.
我目前正在开发一个基于页面视图控制器的iOS项目。一切正常,但是,我想阻止用户超越页面的限制。
In example, when the PageViewController
is positioned in the first page, if the user tries to go to the previous page (even thought there is no one) by dragging the Page View
to the left, the Root View Controller
appears until the drag is released, as you can see in the screenshot below.
例如,当PageViewController位于第一页时,如果用户尝试通过向左拖动页面视图来转到上一页(甚至认为没有人),则会显示根视图控制器,直到拖动被释放,如下面的屏幕截图所示。
Is there any way to block this gesture in the first and the last page of the Page View Controller
?
有没有办法在页面视图控制器的第一页和最后一页阻止此手势?
1 个解决方案
#1
2
Using the PageviewController
delegate method
使用PageviewController委托方法
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
if (indexTest < NUM_OF_PAGES) {
switch (indexTest) {
case 0:{
NSLog(@"Page AFTER is Page: %@", [NSString stringWithFormat:@"%@",[viewControllers objectAtIndex:1] ] );
indexTest++;
return [viewControllers objectAtIndex:1];
break;
}
case 1:{
NSLog(@"Page AFTER is Page: %@", [NSString stringWithFormat:@"%@",[viewControllers objectAtIndex:2] ] );
indexTest++;
return [viewControllers objectAtIndex:2];
break;
}
case 2:{
NSLog(@"No pages AFTER this current page %d", indexTest);
break;
}
default:{
NSLog(@"PROBLEM in viewAFTER, indexTest = %d!!!!", indexTest);
break;
}
}
}
return nil;
}
}
do something like this , with indexTest
is the int variable which increase the page count as per the swipe.
做类似这样的事情,indexTest是int变量,根据滑动增加页数。
NUM_OF_PAGES is the total pages available for page controlling.
#1
2
Using the PageviewController
delegate method
使用PageviewController委托方法
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
if (indexTest < NUM_OF_PAGES) {
switch (indexTest) {
case 0:{
NSLog(@"Page AFTER is Page: %@", [NSString stringWithFormat:@"%@",[viewControllers objectAtIndex:1] ] );
indexTest++;
return [viewControllers objectAtIndex:1];
break;
}
case 1:{
NSLog(@"Page AFTER is Page: %@", [NSString stringWithFormat:@"%@",[viewControllers objectAtIndex:2] ] );
indexTest++;
return [viewControllers objectAtIndex:2];
break;
}
case 2:{
NSLog(@"No pages AFTER this current page %d", indexTest);
break;
}
default:{
NSLog(@"PROBLEM in viewAFTER, indexTest = %d!!!!", indexTest);
break;
}
}
}
return nil;
}
}
do something like this , with indexTest
is the int variable which increase the page count as per the swipe.
做类似这样的事情,indexTest是int变量,根据滑动增加页数。
NUM_OF_PAGES is the total pages available for page controlling.