Using GestureRecognizer on an ImageView in a scrollview - ios

I have a horizontal, paged scroll view that houses multiple view controllers, each of which contains a UIImageView. Within each view controller, I am adding a Tap GestureRecognizer to the ImageView so I can perform a specific action when the image is tapped/double tapped.
However, the ImageView gesture recgonizers don't seem to be firing, and therefore the selectors are not getting called.
I anticipate it may have something to do with the Imageview's being housed in the scrollview, but I am not sure where to start. Is there anything specific I need to do to ensure that the gesture recognizer gets called for each imageview within the scrollview?
Thanks for your suggestions.

Perhaps your UIImageView is not configured to receive user interaction
UIImageView has in default
userInteractionEnabled set to NO. I
would try to change it to YES.
UIgestureRecognizer in a view inside a UIScrollView

Related

Zooming on content view inside of scrollview doesn't work

I'm creating a scrollview with content view inside of it. inside of the content view there are buttons.
from this point, i already can zoom and pan on content view. but when the touch happen on a button the scrollview doesn't zoom.
I have just had the same problem and solved it with the following steps :
Create a UIView.
Create a UITapGestureRecognizer
Add the UITapGestureRecognizer to the UIView to handle taps.
Create a UIButton.
Disable User Interaction (isUserInteractionEnabled = false) on the button.
Add the UIButton as a SubView of the UIView.
In the UITapGestureRecognizer tapped selector, handle the UIButton touchesUpInside call.
Add the first UIView into the UIScrollView.
Make sure the UIScrollView delay content touches delaysContentTouches = true
The UIScrollView should be able to now seamlessly zoom and you can respond to your buttons.
You can skip the button altogether if you want and just handle the Tap in the Gesture Recognizer. I had to do it the way above because the buttons were a custom sub classed buttons and had a lot of additional custom rendering and functionality included.

UITapGestureRecognizer for UIView in Scroll View doesn't work

I have a uiView with added TapGestureRecognizer. This view is showed in scroll view. If the view is visible on the start, when ViewController with scroll view show, everythink is OK.
Problem occurs when the view is not visible on start (when I need scroll ScrollView to see it) then TapGestureRecognizer doesn't call Tap action.
Did you know how to resolve this problem?
As said by wain
The scroll view also has a gesture recogniser. By default, only 1
gesture recognizer can be handling touches at any one time. You need
to make yourself the delegate of your gesture and then implement
gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
to return YES. This will allow it to work at the same time as the
scroll view.
For more detail check Apple's Document link
UIGestureRecognizerDelegate_Protocol
and you can also take reference as Example from below link.
Simultaneous gesture recognizers in Iphone SDK
I hope it will be helpful for you.

UIScrollView scrolling using a gesture on the overlaid view

Consider the view hierarchy in the figure below:
OverlayView is simply a control view that has some custom controls on it. It also has multiple tap/swipe gesture recognizers. The ScrollView is the scroll view that needs to be scrolled based on the interactions with OverlayView. The OverlayView has the same frame as that of the ScrollView.
I need a way to add some kind of swipe/pan gesture setup configured for the OverlayView such that I can scroll the underlying ScrollView as if I am interacting with it.
There seems to be two different approaches:
Recognize the gesture on the OverlayView and pass it to ScrollView. But I am unsure what gestures to use and how to make ScrollView interact with them.
Ignore all the touches on the OverlayView unless they are on the controls. Pass these touches to the underlying ScrollView. This seems like the easier approach; but I am not sure how to proceed with this either.
Does anybody have any kind of sample code for some project or a similar exercise they worked on before? If not, any pointers whatsoever?
Option 2 is what I was going to recommend. There is a method you can override called hitTest:withEvent: on UIView.
You return a view from it. So if the touch needs to go through to the scroll view then return the scroll view. Else return self.

Touches lost on UIScrollview

I am using a UIView subclass which can be resized by dragging on the borders and it is added as subview on a UIScrollView. I am also using a UIGestureRecognizer subclass to move the view on the UIScrollView such that the custom view remains visible and the scrollview autoscrolls.
This setup is working as intended but for one problem. Whenever the custom view is resized, the touches on UIScrollView are lost, i.e the scrollview does not recognise the tap or scroll on it unless the custom view is tapped or dragged once again. I have found that after resizing, neither custom UIView nor custom UIGestureRecognizer's touches began, cancelled or ended are called.
Where might the problem be?

Gesture Recognizer on sub-view outside view's bounds

I'm not sure if this is possible, but I have a view that is able to be dragged around the screen via pan gestures. Once the view is selected, little grippers appear on the corners of the view that allow the user to resize the view. The problem is, those grippers go outside the bounds of the view (they still show up, because clipSubviews is off), but gesture recognizers on those grippers are not firing when selecting the part of them that is drawn outside of the view. Making the view bigger to actually hold the grippers would break a lot of already created logic that is based on the size of the view, so that is a last resort for me.
Is there any other way to get gesture recognizers to work on views that are drawn outside of their parent view?
You could try overriding hitTest:withEvent: in a UIView subclass, and return the gripper view.

Resources