Zooming on content view inside of scrollview doesn't work - ios

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.

Related

UIButton inside of a scrollview isn't clickable

I have an app where I have a couple buttons inside of a UIScrollview. My view hierarchy is like this:
-- UIScrollview
-- UIView (content view)
-- UIView
-- UIButton
-- UIView
-- UIButton
-- UIView
-- UIButton
But the UIButton isn't clickable. Is it possible that the scrollview is blocking clicks? I checked for:
covering subviews;
user interaction enabled = true (on all views);
Scrollview Delay touch down = false;
Scrollview can cancel on scroll = false
The content view clips to bounds. Cutting off anything outside of the view.
but I couldn't find anything.Is there an issue with buttons and scrollviews?
Thanks :)
Is it possible that the scrollview is blocking clicks?
Not inherently, no.
Is there an issue with buttons and scrollviews?
In a word: no. Obviously buttons inside scroll views work just fine all the time. You probably use them every day in many apps that you use.
If your buttons are not tappable in a scroll view, that's because of something you are doing wrong. It is not because of anything in the nature of buttons and scroll views.
Can you check if you have overlapped a UIView with the UIButton.
And enableUserInteraction is not required for UIViews, try disabling it.
Also check if you have linked the right UIButton event with the action method.

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?

Movable UIButtons

Scenario:
There is an UIView as a sub view of a UIScrollView and there is a UIImageView as a sub view of the UIView.
Requirement:
When the user touches on the UIImageView I want to add a UIButton as a sub view at that touch point. Any amount of UIButtons could be added (Within the UIImageView frame). These UIButtons should also be movable inside the UIImageView frame.
What I have done
I have sub classed the UIView and I'm detecting touches using methods touchesBegan, touchesMoved, touchesEnded and adding UIButtons. UIButtons are added with UIGestureRecognizers with a method implemented to the pan gesture.
Problem
When I add more than one button the earlier ones becomes non-movable and doesn't even recognise touch up inside.
Thank you all for the help. I ended up doing this https://github.com/Tulakshana/TTaggableView
You should read about Gesture Recognizers:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html
http://www.raywenderlich.com/6567/uigesturerecognizer-tutorial-in-ios-5-pinches-pans-and-more
Start with UITapGestureRecognizer for showing UIButtons.

Trigger touch event in UIButton embedded in UIScrollView while scrolling

I have a UIScrollView with a group of UIButtons embedded in it. When the UIButtons receive any sort of touch event (while the UIScrollView isn't scrolling) I have them perform an animation that looks like they are being pressed. However, when the UIScrollView is scrolling, the touch event actions of the UIButtons are not triggered. I have attempted to set the zPosition on the UIButtons above the UIScrollView and I have also tried to pass the touch event from the UIScrollView to the UIButton in the same CGRect, but neither of these approaches worked. Let me know what you got...

Using GestureRecognizer on an ImageView in a scrollview

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

Resources