简体   繁体   中英

Draw a path above UIPageViewController

I am now creating an application for kids.This application uses "UIPageViewController". Kids can draw lines inside pages by dragging their fingers.

The problem is that when drag above page that page get flipped: how I can disable page flipping action from certain region so that kids can draw lines there?

Add tap UITapGestureRecognizer in 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];

catch UITapGestureRecognizer delegate method.

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

Override UIPageViewController datasource methods

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM