Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable UIPanGesture on specific UIView #95

Open
JMCPH opened this issue Jun 30, 2020 · 9 comments
Open

Disable UIPanGesture on specific UIView #95

JMCPH opened this issue Jun 30, 2020 · 9 comments

Comments

@JMCPH
Copy link

JMCPH commented Jun 30, 2020

Would it be possible to disable pan gesture for a specific UIView inside a UIViewController?

As the UIPanGestureRecognizer is private, it's not possible to do the following:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
     if touch.view?.isDescendant(of: view) == true {
        return false
     }
     return true
}
@marcosgriselli
Copy link
Owner

I don't think that's possible with the current API but it seems like a feature users will be interested since a lot of views would be better off ignoring that gesture (UICollectionView, MKMapView).

I can take a look at it in the upcoming weeks or help you out if you plan to draft a PR.

@JMCPH
Copy link
Author

JMCPH commented Jul 1, 2020

I would love to make a PR! :-)

@marcosgriselli
Copy link
Owner

Great, let me know if you need a hand with that. Ideally, we'll just find a way to select many views from different screens that will ignore the swiping gesture but I don't have a nice way of achieving that yet.

@JMCPH
Copy link
Author

JMCPH commented Jul 2, 2020

I'm thinking of turning this line:
private var panGestureRecognizer: UIPanGestureRecognizer!

Into this:
open var panGestureRecognizer: UIPanGestureRecognizer!

Then in the UITabBarController we can set the delegate of the panGestureRecognizer to self and then make the check in the following delegate function:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive event: UIEvent) -> Bool {
        return false // Based on the event touch view.
}

@JMCPH
Copy link
Author

JMCPH commented Jul 7, 2020

@marcosgriselli what do you think?

@marcosgriselli
Copy link
Owner

Sure, let's go that way. If we ever need to expand its use case we can search for another approach.

@borut-t
Copy link
Contributor

borut-t commented May 24, 2021

@JMCPH, @marcosgriselli maybe we should build upon that: #103. And add new case none to "AllowedSwipeDirection" enum and just return false for that case inside gestureRecognizerShouldBegin method 🤷‍♂️

@marcosgriselli
Copy link
Owner

@borut-t I don't see a benefit on adding a none swipe direction allowed since we already have a isSwipeEnabled property for the tabBarController. This was originally planned for view controllers with views that required horizontal swiping and covered the entire screen like a map view.

We can extend views to have a property (associated object) that determines if swiping is enabled for that specific view and then check for it on gestureRecognizerShouldBegin. In that way, we can have views that will trigger the transitions and views that won't on the same screen.

@borut-t
Copy link
Contributor

borut-t commented May 24, 2021

@borut-t I don't see a benefit on adding a none swipe direction allowed since we already have a isSwipeEnabled property for the tabBarController. This was originally planned for view controllers with views that required horizontal swiping and covered the entire screen like a map view.

We can extend views to have a property (associated object) that determines if swiping is enabled for that specific view and then check for it on gestureRecognizerShouldBegin. In that way, we can have views that will trigger the transitions and views that won't on the same screen.

Yeah, my bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants