UISlider inside UIPageViewController

痴心易碎 提交于 2019-12-05 01:55:13

Since with UIPageViewControllerTransitionStyleScroll gesture recognizers isn't available, you can use this:

for (UIView *view in pageViewController.view.subviews) {
    if ([view isKindOfClass:[UIScrollView class]]) {
        UIScrollView *scrollView = (UIScrollView *)view;
        scrollView.delaysContentTouches = NO;
    }
}

I solved this issue by add a pan gesture on UISlider and set:

self.sliderGesture.cancelsTouchesInView = NO;  // make touch always triggered

and implement delegate method like:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return otherGestureRecognizer.view.superview == self.parentViewController.view;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    // only receive touch in slider
    CGPoint touchLocation = [touch locationInView:self.view];
    return CGRectContainsPoint(self.slider.frame, touchLocation);
}

You can try to set the delegate of the page view controller gestures to the root view controller:

for (UIGestureRecognizer* gestureRecognizer in self.pageViewController.gestureRecognizers) {
    gestureRecognizer.delegate = self;
}

And then prevent the touch of the gestures if it appears inside UISlider which is a subclass of UIControl:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return ([touch.view isKindOfClass:[UIControl class]] == NO); 
}

What helped me was to add pan-gesture-recognizer to UIView which holds UISlider, so in the end I have UIPageViewController->UIScrollView->...->MyView->UISlider The 'MyView' thing had pan gesture registered to it which did nothing, but served just to NOT propagate events to scroll view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!