How to handle an UIScrollView in an UIScrollView - ios

I want to use an UIScrollView in an UIScrollView. I think it would be clearer with a
picture
The black border is the border of the screen, the purple is the first UIScrollView and the blue is the second UIScrollView. The arrows show the direction of the scroll.
When I try to put the second UIScrollView in the first with a different scrolling direction, the second show the content twice... I made a video

I have created design for you to explain how to add scroll view inside scroll view.
Here see the following image with constraints.
Note: This is static view not dynamic, This is create to clear concept of ScrollView inside ScrollView. If you are planning to make ScrollView with design then you need to do some more study on AutoLayout with ScrollView.

Related

Horizontal scroll view not scrolling

I've just vertical scrolling a few times in the past, but now I'm trying to implement horizontal scrolling but when I run it it doesn't scroll.
What is the problem with it?
P.S. is it possible to design and layout views using a storyboard for scrolling? In this example the blue view is still visible within the screen representation, so its ok to deal with, but suppose I wanted to add another view which is further to the right and thus not visible within the screen representation? Is there anyway of visually designing a scroll view where you can see all the entirity within the storyboard what it will look like?
You don't have a trailing constraint on the scroll view's direct subview, so the scroll view cannot compute the correct contentSize.
Also, it's easier to understand the constraints in the document outline if you give each view a unique label. You have two views labelled “View” so it's difficult to be sure which constraints connect to which “View”.

Interacting with screen behind UIScrollview

I have a view where content is supposed to scroll over a few elements. One of which is a button. What I did is place the button and all background elements, and then created a scrollview on top of that.
However, the touch events now (obviously) go to the scrollview, and not to the elements in the back. Is it possible to enable interaction through the empty parts of a scroll view?
Screenshot here:
There is a scrollview on top of e.g. the "next" and "edit" buttons. but I'd like these to be clickable anyways.
Thanks.
I'm going to assume that the content you want to scroll is in a subview. ScrollViews always serve as the first layer of any scrollable UI. Put scrollview in your subview then UIView over your ScrollView and over that add your elements.

Putting a UIScrollView inside a UIPageView, scrolling doesn't work

I'm making a pageview that has a bunch of scrollable pages inside it. I have the pageview working, and the viewcontrollers that it rotates each have a scroll view inside them. The problem is, I think, that the scrolling doesn't happen because the touches don't get through to the pageview. The scroll view should only scroll vertically, while the pageview works with the horizontal scrolling. Is it possible to send through only the vertical touches, or is there another way?
Thanks
If you're using a storyboard, open the Attributes inspector of the embedded UIScrollView and deselect the "Shows Horizontal Indicator" option. Do the same on the UIPageViewController, but for the "Shows Vertical Indicator". However, you also have to ensure that the scroll view's contents aren't wider than the scroll view itself; to do this, just constrain the contents' width to be equal to the scroll view's parent.

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 ScrollView inside Vertical ScrollView

I have a UIScrollView that scrolls vertically. Inside of that, I have a UIScrollView that scrolls horizontally. I will call them verticalScrollView and horizontalScrollView.
My first problem was that verticalScrollView would scroll up and down, but the horizontalScrollView would not scroll at all. After turning off Autolayout and setting the content sizes in viewDidLoad, the verticalScrollView would always immediately scroll down the bottom upon appearing on screen and only be able to scroll up a little, but the horizontalScrollView (which is at the bottom) scrolls left and right perfectly.
I have tried almost everything that I have found online, but nothing seems to allow me to scroll vertically with the Main ScrollView (verticalScrollView) and scroll horizontally with the child horizontalScrollView.
I can post any more information that may be helpful. Thank you.
UPDATE (8-15-13): I put the hortizontalScrollView into a UIView, and put that UIView into the verticalScrollView. I am now able to scroll freely in the verticalScrollView, but can only scroll one swipe left or right in the horizontalScrollView before it snapping back.
In ViewController.m, I set the content sizes.
[_verticalScrollView setContentSize:CGSizeMake(320, 1905)];
[_horizontalScrollView setContentSize:CGSizeMake(960, 190)];
Please check your Autosizing is top-left or not? May be something wrong in size inspector view in XIB.
Hope this can be helpful to you.

Resources