0
我现在正在为kids创建一个应用程序。此应用程序使用“UIPageViewController”。孩子们可以通过拖动手指在页面内绘制线条。在UIPageViewController上方绘制一条路径
问题是,当在页面上方拖动页面时翻页:我如何禁止某个区域的翻页动作,以便孩子们可以在那里画线?
我现在正在为kids创建一个应用程序。此应用程序使用“UIPageViewController”。孩子们可以通过拖动手指在页面内绘制线条。在UIPageViewController上方绘制一条路径
问题是,当在页面上方拖动页面时翻页:我如何禁止某个区域的翻页动作,以便孩子们可以在那里画线?
添加自来水UITapGestureRecognizer在viewDidLoad中
/** add gesture recognizier */
UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:nil];
singleTap.numberOfTouchesRequired = 1;
singleTap.cancelsTouchesInView = NO;
singleTap.delegate = self;
[_pageController.view addGestureRecognizer:singleTap];
[singleTap release];
抓UITapGestureRecognizer委托方法。
/** recognized tap on pageviewcontroller */
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch: (UITouch *)touch
{
CGPoint touchPoint = [touch locationInView:self.view];
/** detect screen resolution */
CGRect screenBounds = [UIScreen mainScreen].bounds;
if(touchPoint.x > (screenBounds.size.width *0.15) && touchPoint.x < (screenBounds.size.width *0.75))
{
/** tap is on center */
canScroll = NO;
} else {
/** tap is on corners */
canScroll = YES;
}
/** detect the tap view */
UIView *view = [self.view hitTest:touchPoint withEvent:nil];
if([view isKindOfClass:[UIButton class]])
{
canScroll = NO;
}
return NO;
}
覆盖UIPageViewController数据源的方法
/** move to previous page */
- (UIViewController *) pageViewController: (UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
if(canScroll)
{
return _prevPageViewController;
}
return nil;
}
/** move to next page */
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
if(canScroll)
{
return _nextPageViewController;
}
return nil;
}
为什么你需要一个UIPageViewController摆在首位?难道你不能使用正常的UIViewController并且在适当的地方添加UIGestureRecognizers来自己照顾分页吗? – TheEye