Trigger touch event in UIButton embedded in UIScrollView while scrolling - ios

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...

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.

UIScrollView behavior

I have a UIScrollView configured like this :
canCancelContentTouches:YES
delaysContentTouches:NO
Inside the UIScrollView, I have a few UIButtons (think thumbnails). If I click a button, the touch is detected and if I then start scrolling, the touch is cancelled on the UIButton as expected.
The issue I'm encountering is if I give the UIScrollView a good swing, and I stop the scrolling by simply touching the UIScrollView, once I touch a UIButton it will receive the touchesCancelled after approximately 1 second of holding the button, until I re-scroll the UIScrollView
The problem seems to come from the UIScrollView still thinking that it is getting dragged (which is false because i haven't moved yet on my last touch).
Strangely, if I disable bouncing via [UIScrollView setBounces:false] the issue is not there anymore. But I obviously lose the bounce, which is problematic.
I have tried a bunch of thing like disabling/re-enabling the scrollview, its gesture recognizer. I'm running out of ideas here.
What you can do here when uibutton receives touch began you can set uiscrollview contentsize equal to uiscrollview superview size.
When uibutton receives touch end you can set uiscrollview contentsize back to what it was before.
By setting uiscrollview contentsize equal to uiscrollview superview size it will not allow uiscrollview content to move.

Scroll View doesn't scroll when touching and holding then swiping

I have UIScrollView with other UIView elements inside. My other UIView elements are mostly segmented controls. If I click on a UISegmentedControl and hold for a second and then try to scroll, then no scrolling happens. I can only scroll when my finger touches and swipes immediately. I checked other iOS applications such as mail. The behavior was that you touch and hold on a mail, then it's highlighted, but as soon as finger moves away, the scrolling happens and highlighting is undone. How can I implement this behavior?
The issue was the property of UIScrollView. The property canCancelContentTouches was set to NO. Because of that, touch events were handled by subviews of scroll view and swiping didn't cause scrolling.
You can follow one of these steps:
If you are using UISegmentedControl over you UIScrollView, instead of that, add the UISegmentedControl over your controller's view.
If you want to use UISegmentedControl over your scrollView, then you have to create a custom scrollView by creating a subclass of UIScrollView and use an image view instead of UISegmentedControl adding the labels which can act as the segments. This is because your UISegmentControl itself is a touch handler and it breaks the UIResponder chain. So, the scrolling might face issues during the touch events.
Please let me know if any of these works. Thanks :)

How do I pass delayed scroll gestures from a UIButton inside of a UIScrollView?

I have a UIScrollView that contains several UIButtons. Each button is wired up to take an action when the user inputs a touch up event, so they are able to place their finger on the button and it will not be selected until it is raised. Currently, if I made a swipe gesture to scroll the UIScrollView quickly, then the scroll view moves as expected even if the gesture happens directly over a UIButton. HOWEVER, if I hold my finger down too long on a UIButton (about 1 second), the UIScrollView will no longer recognize the gesture and will not be able to scroll until the finger is lifted up.
I am wondering if their is a way to always have the UIScrollView recognize the scroll gesture? Note that this is not an issue if I touch the UiScrollView in a location without a UIButton - it then scrolls as expected.
It may worth a try to let your UIButton respond to UIControlEventTouchDown (maybe with an empty action). I'm not sure if this will work, but conceptually I think it should let the UIButton capture the touch immediately.
(Also make sure you don't enable delaysContentTouches on your scrollview.)
I found the answer to this here: UIScrollview with UIButtons - how to recreate springboard?
Essentially, I had to extend UIScrollView and override touchesShouldCancelInContentView, having it always return YES.

How to Change UIScrollView Sensitivity?

I have this UIScrollView with UIViews in it. Inside the UIView there is a UIImageView which can be dragged in and out of the UIScrollView. The problem is when I tried to drag the UIImageView out of the UIScrollView within 150ms swiping speed, the UIScrollView becomes active and makes the UIImageView impossible to drag out (Swiping diagonally/horizontally).
What I know is, UIScrollView starts a timer during the first touch event and when the touch ended (within 150ms of touch duration), the scroll view will start to scroll. Is there a possible way to change that 150ms touch duration? Or can I disable the touch event when the user swipes diagonally?
Thanks!

Resources