4

Please take a look at the picture below:

enter image description here

I have a custom UIControl as RangeSlider which I implemented by follow this tutorial. I place the RangeSlider inside a FilterViewController which can slide in or out.

On class RangeSlider I used 3 methods of UIControl: beginTracking, continueTracking, endTracking to handle touch event when user move the indicator of slider.

On class FilterViewController I used UIPanGestureRecognizer to handle touch event when user slide in or out.

Problem

When I try to move the indicator of slider, the ViewController also move. And the indicator is just move a bit. It seem to be the both of child view and parent view received touch event.

Question

How can I ignore the parent view(ViewController) receive touch event?

3 Answers 3

0

You can write this in viewDidLoad().

self.view.isUserInteractionEnabled = false
Sign up to request clarification or add additional context in comments.

2 Comments

What is use of it?
Your parent controller view will not receive any touch events.
0

You should implement method of your PanGestureRecognizer delegate

gestureRecognizerShouldBegin(_:)

edit: please try

override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
    guard let view = gestureRecognizer.view, view.isKind(of: UIControl.self) else {
        return true
    }
    return false
}

Hope this helps.

1 Comment

I have to observe every controls and check if whenever touch event happen with my controls. Is there any way easier or less complicated to solve my problem?
-1

This should help within FilterViewController (assuming it is touch delegate)

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isDescendantOfView:self.tableView]) {
        return NO;
    }

    return YES;
}

Sorry for example in objective-c, you can easily convert it into swift. It means that the table or scrollview you use won't react on touches of its subviews (assuming RangeSlider is descendant subview of table view cell). Let me know if that doesn't help, I forced these issues in past by several different ways!

2 Comments

I tried to use that way but it is not work. The problem is: I only want my ViewController's View ignore touch event when it occurs on my RangeSlider but not the other subviews of ViewController's View.
got you! if ([touch.view isDescendantOfView:self.slider]) { doesn't work as well? Sorry, can't help in greater details without code, maybe you can share some little test project?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.