I already know how to attach a swipe gesture to view.
Suppose I have a tiny view (0,0,5,5).When I swipe in it, the action with that gesture is not trigger. Then I debugged, I found out the tap event I attached with this view interfere the swipe. How can I make the swipe action trigger with that tiny view?
Summary, with a same view, if it's tiny - the Tap gesture will handle the action. If it's bigger, the swipe gesture will handle it.
Related
I want a user to normally be able to swipe right to left through the pages of the page view controller, but I also want the user to swipe up on a page to save the content of that page. So far I have tried adding a gesture recogniser but it interferes with the page view controller. I have tried many thins like adding the gesture recogniser to the window, or a hidden view but it keeps messing with the page view controller.
All in all is there a way that mainly horizontal swipes get picked up by the page view controller(so they move to the next viewcontroller), but vertical swipes are picked by by me and I can play an animation and trigger a function or something...
It looks like UIPageViewController exposes its gesture recognizers with the property gestureRecognizers.
You should be able to attach your swipe up gesture recognizer to the page's view.
You'd then tell your gesture recognizer that it should only work when the page view controler's gesture recognizers fail. You'd call your gesture recognizer's require(toFail:) method for each of the page view controller's gesture recognizers.
(You should read the Xcode documentation on UIGestureRecognizer. It explains how you can set up dependencies between gesture recognizers so that one has to fail before the next one will evaluate, for situations like this one.)
In my app I've coded a side menu that looks like this:
Here's the code that is called when I tap a menu button that's in some views:
How can I have the menu slide in to view (depending on where the user's dragging finger is) and swipe away? And also go away when I tap the dimmed view on the right.
Any help is appreciated.
One way to achieve this is using the gesture recognizers in swift.
To tap and dismiss the menu control, use UITapGestureRecognizer, bind it with a selector method and dismiss the controller/ view you are presenting. Check out the link to apple documentation for TapGesture : Guide
For swipe gesture, add Swipe gesture UISwipeGestureRecognizer to the UIView, and write the dismiss method using slide animation for smooth UI. Swipe Gesture Guide
Let me know if you need any more help.
I have two Swipe Gesture Recognizers on my ViewController. One works fine, when I swipe right it goes back to the previous View. However, the recent one I added doesn't work at all. I have set it to go to a different View Controller when I swipe left but, nothing happens. I didn't add any code for the first Swipe Gesture Recognizer so shouldn't this additional one also be able to work without code?
It goes back because the interactivePopGestureRecognizer handles that, not your swipe recognizer.
You need to do two things:
Wire your gesture recognizers to IBAction calls within your view controller so that it can handle them
Disable the pop gesture recognizer so that it will not conflict with your desired behavior (See answer here for how)
I have 4 ViewControllers that I want to navigate through by swiping left and right from the edge of the screen. I am fairly new to ios, so was just wondering if it would be more beneficial to activate a segue by using a Screen Edge Pan Gesture Recognizer or by using a UIPageViewController. It is worth noting that the ViewControllers all contain gesture recognizers, imageViews, textViews' etc. I do only want to switchviewControllers` when swiped from the edge of the screen.
If you use edge swipe gesture recognizer, you're going to have to write code to manage the view controllers. If you're new to iOS, I might suggest using the page view controller, so it gets you out of the weeds of managing this yourself.
Both can work, but I'd suggest starting with the page view controller and only "roll your own" if the page view controller doesn't give you the control that you need.
In my app the user can tap anywhere on the screen and a slide down view will appear covering half the screen. If they tap anywhere again then the view will disappear.
in order to implement this I've added a tap gesture recognizer to the main view within the storyboard.
However within the slide down view there is a button with an associated action, when the user taps the button the action is getting invoked but also additionally the tap gesture recognizer is being invoked.
When the user taps the button how can I disable propagation of the tap event to the gesture recognizer?
When you press the button both functions will be called so in the function that responds to the tap gesture. Check if the location of the tap is within the frame of the UIButton. If it is just return from the function.