UIScrollview + autolayout doesn't seem to work in iOS8 / Xcode 6 preview?

The following steps for autostarting UIScrollView + work for me, but not in the iOS8 / Xcode 6 preview: (using the storyboard, the size class is included):

  • add scrolling to root mode.
  • output zero spaces in all edges of the superview.
  • add a UIView (contentView) to the scroll above.
  • prints zero spaces to all scroll edges
  • add some widgets to the contentView and change the height of the contents of the View to 2000.

=> This scroll content scrolls in iOS 7, but I cannot perform the same actions as in the preview of iOS 8.

It even seems to work in iOS 7, maybe I can't do the right way? Any suggestions?

+8
autolayout ios8 uiscrollview
source share
2 answers

I am surprised that I have not seen more comments about this. The scroll view of the internal autostart is mostly broken in iOS 8 (as seeded before the time of writing).

EDIT . This was fixed in seed 5, so this note should be ignored!

It is assumed that this rule (see https://developer.apple.com/library/prerelease/ios/technotes/tn2154/_index.html ) if the contents of the scroll (its subspecies or subtitles) are attached to all four scroll borders, it sets the size of the content.

However, in iOS 8, this fails - but in an odd way. It fails only if the restrictions determining the height and width of the subzones are absolute, not internal.

Thus, for example, consider the code at the bottom of this technical note, where the code creates a scroll and a really large image (here it is: I fixed a small typo where we omit the at sign):

- (void)viewDidLoad { UIScrollView *scrollView; UIImageView *imageView; NSDictionary *viewsDictionary; // Create the scroll view and the image view. scrollView = [[UIScrollView alloc] init]; imageView = [[UIImageView alloc] init]; // Add an image to the image view. [imageView setImage:[UIImage imageNamed:@"MyReallyBigImage"]]; // Add the scroll view to our view. [self.view addSubview:scrollView]; // Add the image view to the scroll view. [scrollView addSubview:imageView]; // Set the translatesAutoresizingMaskIntoConstraints to NO so that the views // autoresizing mask is not translated into auto layout constraints. scrollView.translatesAutoresizingMaskIntoConstraints = NO; imageView.translatesAutoresizingMaskIntoConstraints = NO; // Set the constraints for the scroll view and the image view. viewsDictionary = NSDictionaryOfVariableBindings(scrollView, imageView); [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|" options:0 metrics: 0 views:viewsDictionary]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|" options:0 metrics: 0 views:viewsDictionary]]; [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]|" options:0 metrics: 0 views:viewsDictionary]]; [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView]|" options:0 metrics: 0 views:viewsDictionary]]; } 

This code works (assuming you have a really large image), because the image is sized according to internal restrictions. But now change the last two lines, for example:

  [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView(1000)]|" options:0 metrics: 0 views:viewsDictionary]]; [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView(1000)]|" options:0 metrics: 0 views:viewsDictionary]]; 

Now you have a scroll that scrolls on iOS 7 but not scrolls on iOS 8. Further research shows that this is because the content size remains at (0,0) ; it does not take into account the absolute restrictions on the width and height of the presentation of content.

+7
source share

Use the next step for UIScrollView + AutoLayout

  • Add scroll view to root mode
  • Add a scroll view to the top.

Add the following restriction to view the scroll

  • Trailing space for superview = 0
  • Leading space for super view = 0
  • Top space for super view = 0
  • Bottom Space to super view = 0

Add the following restrictions to display the scroll view (in this case, the scroll view is a super-view)

  • Trailing space for superview = 0
  • Leading space for super view = 0
  • Top space for super view = 0
  • Bottom Space to super view = 0
  • The height of the content view (if you use vertical scrolling), otherwise the width of the content view (if you use horizontal scrolling).
  • Orientation of the horizontal gallop (if you use vertical scrolling), otherwise vertical alignment of the gallop (if you use horizontal scrolling).
0
source share

All Articles