GestureRecognizer and IBOutlet don't work together - ios

I'm creating an iPhone app. In my main view, I have a subview. When I add a gesture recognizer to this subview, and I connect it to an action in my view controller, it works : the action method is called when the gesture is performed.
But when I connect my subview to an outlet in my view controller, suddenly, the gesture recognizer doesn't work anymore.
I have recreated this simple situation in a blank project, and here it works... Have you an idea about the origin of my problem please ?

So after reading your comment, I understand that the problem was indeed that you "messed" with the IBOutlet instance in your viewDidLoad as I presumed.

Related

Why Tap Gesture Recognizer to dismiss keyboard has Referencing Outlet Collection gestureRecognizers-View?

The purpose of my Tap Gesture Recognizer is to dismiss the keyboard if the user touches any part of the screen outside the keyboard.
The Tap Gesture Recognizer has a referencing outlet collection named gestureRecognizer connected to the root View of the View Controller. I don't know why this is necessary or how to use Referencing Outlet Collections in general. I'm very curious why this is necessary for my Tap Gesture Recognizer. I do not see any code related to the gestureRecognizer in my .h or .m files for the ViewController.
I found the code for this Tap Gesture Recognizer from a tutorial out there on the interwebz so I don't know exactly why they programmed it the way they did. Would really like to know.
Thank you!

Why isn't the swipe gesture triggering a segue to the next view?

I've added a swipe gesture recognizer to a UICollectionView on storyboard, with a Navigation Controller set up. I'm following this tutorial, except I'm using an UICollectionView for the first view.
The actual problem is that when I run the program, and I try to swipe, nothing happens. Everything else happens.
I have tried following the directions over and over and in different ways, but nothing seems to work. I've created another project and just using regular view, it worked fine, which makes me think that the UICollectionView is part of the problem. Am I putting the gesture recognizer in the wrong view? I've tried putting it in the UIView of the first View Controller and in the UICollectionView, but it doesn't work.
What am I doing wrong?
Clearly, if I left any information out or you need any information at all, please don't hesitate to ask in the comments for it.
EDIT: The connections of the swipe:
Did you have define in storyboard, the segue from swipe gesture to next viewController ?
did you swipe in the correct direction (this can be set in storybord, select your swipe, attributes inspector, Right / Left / UP / Down
The UICollectionView Is probably taking the gesture over and telling the controller that It cannot handle the collection view gesture and your swipe gesture at the same time. Implement the UIGestureRecognizerDelegate protocol and return YES in this delegate method - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer. Make sure that the delegate of the swipe gesture is set on the controller from the storyboard.

Prevent UIScrollView's UIPanGestureRecognizer from blocking UIScreenEdgePanGestureRecognizer

I have a UIScrollView that fills the screen on one page of my app, but I want to allow the user to pan from the edge of the screen to reveal a view behind it. The problem is that the UIScrollView steals the touches from my UIScreenEdgePanGestureRecognizer at the edge of the screen. Unfortunately, I can't access the UIScreenEdgePanGestureRecognizer from the view controller that has the UIScrollView (and vice-versa), so I am not able to use the method requireGestureRecognizerToFail: because I cannot able to specify which gesture recognizer should be allowed to fail. The view controller with the scroll view is a child view controller of a container view controller that has the screen edge pan gesture recognizer attached to one of the container view controller's own views.
I'm also unable to use the delegate method
-(BOOL)gestureRecognizer:shouldRequireFailureOfGestureRecognizer:
because the UIScrollView won't allow me to set my view controller as the delegate of the scroll view's UIPanGestureRecognizer.
How can I prevent the scrollview from stealing the edge pan touches from my own gesture recognizer?
Unfortunately, creating this behavior can be a real P*** i* t** A**.
Fortunately, creating this behavior is possible using the UIGestureRecognizer Delegate even if you can't access one GestureRecognizer directly.
-(BOOL)gestureRecognizer:shouldRequireFailureOfGestureRecognizer:
-(BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
-(BOOL)gestureRecognizer:shouldBeRequiredToFailByGestureRecognizer:
The second parameter ('otherGestureRecognizer') passed in the delegate methods holds the UIScrollView's PanGestureRecognizer (or private Apple - subclasses) when your gestureRecognizer 'collides' with the scrollView's.
So simply set your UIScreenEdgePanGestureRecognizer's delegate to reply to the delegate methods.
The naming of these two methods is very suboptimal and to be honest, i don't really know what the correct return values for your case are.
I just had this problem yesterday and i solved it by brutal trial & error.
Im my case, returning NO from both shouldRequireToFail and shouldBeRequiredToFail methods and YES from the simultaneous-method solved my problem.
Note: Returning NO from both methods changed the behavior compared to not
even implementing the methods at all. Even though the documentation says
the default return value is NO.
However, ANY GestureRecognizer behavior can be achieved by using the delegate methods. But as i said above, the naming of the methods is just very confusing. + there is as much as NO useful documentation for these methods.
This can be done without having to set the screen pan gesture's delegate to your view controller.
[scrollView.panGestureRecognizer requireGestureRecognizerToFail:screenPanGesture];

How do I add a segue to an UIGestureRecognizer

I am building an app for the first time using Storyboards. I have a scene which I would like to have open another scene when there is a long tap on a particular button. I am able to add the UILongPressGestureRecognizer with no problem, but I can't figure out how to have that gesture be the segue to the other scene. Doesn't seem to matter what I Ctrl-Drag, nothing works.
Am I missing something obvious?
Thanks,
Ken
You can control-drag from your first controller's window to your second controller to create the segue, and then you can call performSegueWithIdentifier in your GestureRecognizer method.
It's now possible to do it all in your Storyboard visually. Every gesture recognizer has Triggered Segues in Connections Inspector.

iOS 5.1 UIView to call super ViewController's selector

In my project i have an UIView instance and attached a gesturerecognizer to it. In case that gesture is recognized i want to call its parent viewcontroller to reorganize the scene.
Here's how it's implemented
The UIViewController is called HomeViewController.
It has one subview which is a UIScrollview.
The UIScrollView contains several UIView instances.
To all of these UIView instances i attached a gesture recognizer. When it fires i want to disappear and call the HomeViewController's reOrganizeUI method.
My problem is that i can't reach the HomeViewController from the UIViews.
Is there a way to do this?
Sincerely, Zoli
Surely you can. The simplest way to do this is to add a property to all your UIView subclasses and assign your HomeViewController to that property when creating the views in the view controller's initialization method. Then you'll be able to access the controller from the views directly.

Categories

Resources