How do I prevent a scroll view from letting a user (temporarily) scroll a UIScrollView out of it's content area? - ios

UIScroll view lets me declared a scrollable area when I have too much content for one page. Strangely, the scroll view in question behaves as desired in the X-axis, with no scrolling whatsoever allowed. Unfortunately, the Y axis -- where scrolling is necessary -- doesn't 'clip' the allowed scroll area to the content size. The user can scroll outside of the content size, and only after they let go does scroll view 'bounce' back to the allowed zone.
I want to prevent the user from scrolling further up than there is content to view (down doesn't bother me) because it looks 'wrong' to have the header at the top of the scroll view pull down, leaving the regular background behind it.

If you are making your UIScrollView in interface this is as simple as deselecting the
"Bounces, Bounces Horizontally, and Bounces Vertically"
check boxes in your scrollView's attributes. If you are designing the UIScrollView in code you can add this.
self.textView.alwaysBounceHorizontal = NO;
self.textView.alwaysBounceVertical = NO;
self.textView.bounces = NO;

Related

Voice over accessibility paging problems for scroll view with content inset

Consider the following scenario: A UIScrollView with content inset of top: 500. In this area there is a subview.
When "three finger swiping" to go "to the next page" of the scroll view, the UIScrollView insists that it should never scroll above it's content offset 0. Sometimes it actually scrolls there and says (Page ZERO of 3), but after a while it never jumps there. Is there any way of also including the "content inset" area in the page scrolling?
Here is some test code that replicates this behaviour. Our actual user case is more complex but this is the basic idea:
https://gist.github.com/ullstrm/45bd68032fe92ba13476b506ed70f424
The View Controller has just a single scroll view with all edges constrained to superview with constant 0.
Any ideas of how to let iOS know that it should scroll to this area as well?
You can override Voiceover's scrolling behavior using the accessibilityScroll method. You'll need to manually change UIScrollView's contentOffset, but otherwise it should work just fine.

How to prevent a non-scrollable UIScrollView from stealing scroll event?

To elaborate on my question, I've three scrollviews one top of another, let say base, middle and top. Base scroll view's content size is more so it will scroll, middle scrollview's content size is equal to its frame so it will not scroll, top scrollview's content size is more than its frame so it will also scroll.
Now when I scroll the top scrollview, once it reaches its end, I"m expecting it would scroll the base scroll view as middle is not scrollable. But it seems middle scroll view consumes all my scroll events and not letting the scroll event to go to base scroll view.
I"ve tried by setting more content size to middle scrollview, then it working as expected, first top scroll view scrolls fully then it passes the scroll event to middle scroll view then to the base scroll view.
Now it is more evident that middle scrollview (which is non scrollable) is consuming all of my scrolling event from going to base scroll view. How do I prevent that.
Note : As I've to support zooming, I need scroll view in all three levels.
Any help would be really appreciated.
Thanks.

How to stop iOS app from scrolling up

I made a Content View inside Scroll View added constraints using common Autolayout with UIScrollView tutorials. But how do I stop my Scrollview from scrolling up when there is no content, the view slides down to content, but I want to disable scrolling up, I searched for the answer but there is none to be found, please help.
The ability to scroll slightly beyond the content in a UIScrollView is referred to as "bouncing".
The scroll view must know the size of the content view so it knows when to stop scrolling; by default, it “bounces” back when scrolling exceeds the bounds of the content.
You need to set bounces to no:
If the value of [bounces] is YES, the scroll view bounces when it encounters a boundary of the content. Bouncing visually indicates that scrolling has reached an edge of the content. If the value is NO, scrolling stops immediately at the content boundary without bouncing. The default value is YES
scrollView.bounces = NO;

iOS 7.1 Why is my UIScrollView scrolling away on showing keyboard?

I have a UIScrollView designed with IB.
UIView
UIScrollView
UIView
UITextField
UIButton
...
If I tap on the text field the view scrolls away towards the upper left corner of the screen before the keyboard is appearing. The space above the keyboards remains empty. I can scroll back the view if I drag in this empty space.
I have googled around, but found only postings where users want to scroll UIScrollView. I want the view to stay where it is.
Thanks in advance for any suggestions.
Here's what happened.
You designed the whole thing in Interface Builder.
The scroll view was not scrolling, so you set its contentSize in code to the size of the scroll view's primary subview (what I like to call the content view).
The scroll view was still not scrolling, so you munged the content insets - and this caused the problem that brought you here.
Your mistake was (3). Instead, you should have thought more about (2), i.e., why isn't my scroll view scrolling even though I have given it a nice big content size?
The answer is that, in a storyboard or xib that has auto layout turned on, that's not what you do. What you do is use constraints from the content view to its superview (the scroll view), on all four sides. Set the constant for all four constraints to zero. This causes the content size to match the size of the content view, automatically.

horizontal scrolling of a scrollView in a scrollView - small problem

i have a scrollView that fits the whole screen. In that View i show some UIImages that scroll horizontally. Like in the PageControl Project from Apple.
Then, when the user taps the screen, i fade in a scrollView at the bottom with some other images. Also horizontally scrolling. Like in the ScrollView Project from Apple.
My problem is, that when i come to the end of the scrollView which was faded in, the upper scrollView also starts to drag. How can i stop that during activation of the second scrollView?
Redraw the frame limits on your first scrollView when the second enters the screen. That way, your touches won't respond to both views. This means you need a container-view to keep both views seperated from each other.
Then you just rescale it back whenever your second scrollView disappears.
Edit: or disable scroll in your first scrollview while the second is open.

Resources