4

I'm having difficult dealing with the designing a layout that fits both 3.5inch iphone and 5 inch iPhone (Simulators). I had auto layout checked, and all the layouts were perfect. However I now need to use a UIScrollView, and therefore need to uncheck auto-layout to use.

Also when viewing the layout with an iPhone 4 inch display its adds about 60px to the top of the UIScrollView.

Is there a better way to do this (set up scrollview without deselecting auto-layout)? So i can support iPhone 4.

//to set up the scrollview
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:CGSizeMake(320, 800)];

however it does not scroll until I uncheck the autolayout. Is there a better way to do this?

DevC
  • 6,982
  • 9
  • 45
  • 80

4 Answers4

1

Try autoresize,

 self.scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
karthika
  • 4,085
  • 3
  • 21
  • 23
0

UIScrollView when using Autolayout is slightly different. You need to do some modifications. You answer is here.

Community
  • 1
  • 1
iOS
  • 3,526
  • 3
  • 37
  • 82
  • Thanks for the comment, I tried implementing what was suggested but I think I got a bit lost, I created a subview and added it do scrollview rather than adding the uiElements to it `[scrollView addConstraint:[NSLayoutConstraint constraintWithItem:lastSubView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:scrollView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]];` – DevC Oct 10 '13 at 11:16
  • Now are you using Auto layout? Checked Auto-Layout? Did you add `translatesAutoresizingMaskIntoConstraints = NO;` if you are using Auto layout? – iOS Oct 10 '13 at 11:34
  • I was using AutoLayout but I was not using `translatesAutoresizingMaskIntoConstraints = NO;`, will this make it work? – DevC Oct 10 '13 at 11:47
0

You can do something like this to your UIScrollView frame. Assign frame to scrollview as per below CGRect.

CGRect rect=[[UIScreen mainScreen] bounds];

Hope, this will work for you.

Sunil Targe
  • 7,251
  • 5
  • 49
  • 80
0

Try this (it solved my problem):

scrollView addConstraint:[NSLayoutConstraint constraintWithItem:lastSubView
                                         attribute:NSLayoutAttributeRight
                                         relatedBy:NSLayoutRelationEqual
                                            toItem:scrollView
                                         attribute:NSLayoutAttributeRight
                                        multiplier:1.0
                                          constant:0]];

REFERENCE: UIScrollView doesn't use autolayout constraints

Community
  • 1
  • 1
Roozbeh Zabihollahi
  • 7,207
  • 45
  • 39