Pergunta

I have UIPageViewController with transition style scroll and navigation orientation vertical. In one of the UIViewControllers I have a UITextView. When I try to scroll inside the text view sometimes UIPageViewController catches the pan gesture and tries to move to next view controller. What would be solution to stop UIPageViewController to receive touch events when a user scrolls text view?

I tried to set exclusiveTouch=YES for the text view, but it didn't help.

Foi útil?

Solução

I found a solution. You can disable UIPageViewController panning when UITextView is scrolling.

To disable or enable UIPageViewController panning:

-(void)enablePanning:(BOOL) enable
{
    for (UIScrollView *view in self.pageViewController.view.subviews) {
        if ([view isKindOfClass:[UIScrollView class]]) {
            view.scrollEnabled = enable;
        }
    }
}

And to know when UITextView is scrolling we can use UITextViewDelegate methods:

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    [self enablePanning:YES];
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
     [self enablePanning:NO];
} 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top