UIScrollView behavior - ios

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.

Related

How to disable scroll of the UIScrollview when it is in pannable?

I'm working on moving the UIView inside the UIScrollView. If the UIScrollView is not pannable then I could manage to trigger the TouchesBegan and TouchesMoved events but when the UIScrollView is zoomed and if I try to touch and move the UIView, scrollview is intercepting and started scrolling. I could not move the UIVIew freely across the UIScrollView.
Can anyone suggest me how to resolve this issue?
Solution:
I have found the solution by setting the UIPanGestureRecognizer ShouldRecognizerSimultaneously to true.

Disable UIScrollView scrolling with second finger if already dragging

I have UIScrollView with a UIImageView. The user is able to pan the image vertically.
How do I stop the user from continuing dragging with another finger, or ignore a second touch on the scrollview? Somewhat similar to the dragging behaviour in the photoBrowser of the Facebook app.
Try setting both the canCancelContentTouches and delaysContentTouches properties of your UIScrollView to YES.
When the UIScrollView property canCancelContentTouches is set to YES, it should transfer any scrolling/drag touches to the scroll view and cancel whatever that touch would have been registered in the subview.
The scroll view's delaysContentTouches should be set to YES as well. This will prevent drags from being triggered as taps (because the handler fires off too soon).
and also try this link
http://www.cocoanetics.com/2010/06/hacking-uiscrollview-gesture-recognizers/

How to touch UISlider thumb prevents UIScrollView scrolling

I have seen many similar questions to this but none help me exactly. I have many vertical UISliders filling a wide UIScrollView. If I drag the thumb on the slider I want the horizontal UIScrollView to be locked and only allow vertical sliding. If I drag the UISlider other than on the thumb I want the horizontal UIScrollView scrolling. It currently works if I touch the thumb before dragging.
I have overridden touchesShouldCancelInContentView in the scroll view but never hit the breakpoint in that method.
I had to override touchesShouldBegin:withEvent:inContentView and also set delaysContentTouches to NO to intercept the touch message.

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