Horizontal ScrollView inside Vertical ScrollView - ios

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.

Related

How to handle an UIScrollView in an UIScrollView

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.

Scroll bar scrolls but UIScrollView doesn't scroll

I have components in a UIScrollView. My scroll view works when it was in iOS 10 and Xcode 8 but after the update, my scroll view does not scroll. However, the scroll bar does scroll and can keep scrolling until it gets smaller and smaller. It is just the elements in the scroll view itself that doesn't scroll.
I have tried doing content size bigger than the frame size but it does not fix it. Here is my current views hierarchy.
If anyone can help me debug this, it would be greatly appreciated.
I fixed this by adding a content view to the scroll view, and then the scroll view should be the subview of main view. The hierarchy should look like this.
I encountered pretty much the same problem (scroll indicator moves and gets smaller but content doesn't move). In my case it was resolved by changing the AutoLayout constraint for the top of my content view within the UIScrollView. I had pinned it to the Frame Layout Guide rather than the top of the superview.

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.

ScrollView changes suddenly its position

I've a very strange problem with my scrollView.
First of all, this is my scrollView:
...and in my viewDidLoad:
_scrollView.contentSize = CGSizeMake(320,500);
The scrollView seems to work when I start the app. But when I scroll down to the bottom of the scrollView and click another tab in the tabBar while the scrollView is still at the bottom, and then go back to the tab (ViewController) with the scrollView, there is free space at the bottom added (which wasn't there before), but in return the top of the scrollView cuts off my content which is positioned at the top. >>> The space which appears on the botton is left on the top of the scrollView
This only happens, when you go to another tap while staying at the bottom of the scrollView.
I know this is very difficult to explain, but I hope you understand my problem and can help me.
I set the content the following way:
-viewController
-View
-Scroll View
-buttons, images, etc.
-tabBar item
-navigationItem
I've found a solution now:
-(void)viewWillAppear:(BOOL)animated{
[self.scrollView setContentOffset:CGPointZero animated:NO];
}
...I now this solution is not 100% good, but for my problem its ok :)

Resources