1

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)];
tagabek
  • 1,956
  • 4
  • 16
  • 22
  • have you explicitly set frame for both along with content size? – NightFury Aug 15 '13 at 08:46
  • are u setting content offset somewhere in `viewDidLoad` or `viewWillAppear`? It is responsible for self scroll. – NightFury Aug 15 '13 at 08:50
  • Only allow Vertical Scrolling in _verticalScrollView and horizontal scrolling in _horizontalScrollView. This link may help you:http://stackoverflow.com/questions/728014/uiscrollview-paging-horizontally-scrolling-vertically – Puneet Sharma Aug 15 '13 at 08:52
  • I explicitly set the frame for the verticalScrollView and it still scrolls down to the bottom immediately, and some of the objects seem to be out of place. – tagabek Aug 15 '13 at 08:54
  • @anum90 I have not set the content offset anywhere – tagabek Aug 15 '13 at 08:57
  • Ok. NSLog your current offset and let me know if setting it works. `verticalscrollView.contentOffset = CGPointMake(0, 0);` – NightFury Aug 15 '13 at 09:00
  • @anum90 I NSLogged my contentOffset before setting it via verticalscrollView.contentOffset = CGPointMake(0, 0); , and the NSLog returned (0.0000, 0.0000) for both the verticalScrollView and the horizontalScrollView. Setting it to (0, 0) seemed to do nothing. Thanks for your help though. – tagabek Aug 16 '13 at 04:50

1 Answers1

0

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.

Nishith Shah
  • 523
  • 3
  • 16
  • The "Mode" in the Interface Builder is set to Scale to Fill and not Top Left, if that is what you mean. I checked out the Size Inspector, and nothing appears to be wrong. – tagabek Aug 16 '13 at 09:02