在UIPageViewController上面绘制一条路径

时间:2013-06-06 08:06:48

标签: ios uipageviewcontroller

我现在正在为kids创建一个应用程序。这个应用程序使用“UIPageViewController”。孩子们可以通过拖动手指在页面内画线。

问题在于当页面上方的页面被翻转时:如何禁用某些区域的页面翻转操作以便孩子们可以在那里画线?

1 个答案:

答案 0 :(得分:1)

在viewDidLoad中添加点击UITapGestureRecognizer

/** 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;
}