Prevent UIScrollView scrolling if slide gesture is in a rea - ios

I have a UIScrollView and a subview of that view is a UISlider. I am finding that when I try to slide the UISlider the UIScrollView scrolls.
Can I make it so the scroll view only slides if I am not touching the UISlider?

You could use this self.slider.exclusiveTouch = YES;
From the Apple Documentation:
Restrict event delivery to a single view. By default, a view’s exclusiveTouch property is set to NO, which means that one view does not block other views in a window from receiving touches. If you set the property to YES for a specific view, then that view receives touches if—and only if—it is the only view tracking touches.
So by setting your slider's exclusiveTouch property, you can prevent scrollView from receiving the touches and therefore it will not slide.

Related

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?

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 :)

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/

setExclusiveTouch ignored when using UISwipeGestureRecognizer

I have two UIViews (custom scroll views) that respond to UISwipeGestureRecognizer. These two UIViews are subviews of the parent UIView. I want to allow only one of the subviews to respond to the recognizer.
In other words, only one should be allowed to be swiped at a time.
Setting setExclusiveTouch = YES on the subviews AND/OR the parent view doesn't have any effect.
How can I make sure that only 1 subview is being swiped at a time?
Here's a picture:
UIScrollView's by default have multipleTouchEnabled set to YES - if you do not need multiple touch (zooming for example requires it), then set it to NO.

How do you receive touches in views added to a subview

I have been adding several subviews ("touch subviews") to a scroll view which respond to touches. The touch delegate methods in each of these subviews all fire nicely.
I have one subview (bodyClock) which holds the main content of the scroll view and is the viewForZoomingInScrollView. In order for the "touch" subviews to zoom properly I find now that I have to add them the bodyClock subview instead of the scroll view. When I do this, however, the "touch subviews" no longer respond to touches.
I have tried all sort of things with first responder without any success. Any help pointing me in the right direction would be appreciated.
OK, I found my problem I had a subview acting as a time mask in the scroll view that I think was responding to touches. This became evident when I noticed that the touch subViews did not respond to touches while the mask was over them. Because the mask was a subview to the scroll view, it would move when zooming such that a touch subview in the bodyClock view would come out from underneath the mask and suddenly start working.
Moving the mask from the scroll view to the bodyClock subView along with the "touch subviews" fixed my problem. Now all the subviews scroll and zoom properly, and respond to touches.

Resources