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.
Related
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.
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 :)
I have a UIScrollView stretching over the entire screen, which the user is able to scroll vertically only. Right 'above' it is a UIView with a few buttons, which covers the bottom 120 px only. The user may tap the buttons to invoke their selectors. But I wish to be able to pass the panning movement to the scrollView, so that the user may scroll the scrollView if they pan with a velocity greater than a certain threshold, if the panning begins over the UIView.
How would I go about it?
Thanks
You can do 2 things.
Add a UITouchesMoved function to your uiView, calculate finger movement and move your scrollView accordingly by scrolling it to a CGPoint.
You can use UIPanGestureRecognizer.
I have a UIScrollView with an button just outside the content area of the scrollView. The user has to scroll up and hold the spring effect which one finger and push the button with another finger. The problem is that the touch on the button is never detected.
Please see the illustration below
The scroll view in it's initial state. the orange area is the scrollView, the white area the button
The user is now scrolling and holding with one finger to overcome the spring effect of the UIScrollView, and want to click the button
Any suggestions?
Check this out:
UIScrollView blocks all touches while zooming or scrolling
Make sure you have multitouch set to YES on the scrollview and also don't have any subviews with exclusive touch enabled.
I have a multidirectional UIScrollView within a horizontal UIScrollView within a vertical UIScrollView. When I reach the horizontal content limit of the innermost scrollView, the containing horizontal scrollview begins scrolling just as I want.
But when I reach the vertical content limit of the innermost scrollView, I do not get any action on the top level vertical scrollView.
If all vertical content is visible at innermost level (so no vertical scrolling is possible), then the top level vertical scrollview takes over fine. Any clues on how to fix this?
I get this same behavior with Apple "PhotoScroller" sample code if I embed their photo paging scrollView in a vertical scrollView. If the photo is not zoomed, then both the horizontal and vertical scrollviews will work. If the photo is zoomed but panning stops because it has hit the horizontal or vertical limit, then only the horizontal scrollview works.
This is using an older version of the sample code that implements the photo paging as a UIScrollView rather than UIPageViewController. With current UIPageViewController version, paging is not possible when the photo is zoomed.
To answer my own question, I used gestureRecognizerShouldBegin: delegate to determine whether the innermost scrollView was at a boundary when the pan gesture began. If so, I responded to shouldRecognizeSimultaneouslyWithGestureRecognizer:
delegate to enable the UIPanGestureRecognizer on both the inner scrollView and the vertical scrollView. This allowed a single gesture to scroll both simultaneously. Then, I over-rode setContentOffset on both scrollViews to suppress the scrolling on the wrong one.
I think a better answer is probably to replace the UIPanGestureRecognizer on the inner UIScrollView with a custom gesture recognizer that cancels itself when started at a boundary and dragging past the boundary. But, I could not get that to work.
Still not clear to me why the horizontal version of this just worked automatically. Perhaps there is some special case handling in the UIScrollViewPanGestureRecognizer to handle horizontal case, or interaction with immediate superView.