Extra space (insert) in scroll view at runtime

Customization

I am working on a view in Xcode 5 that displays a set of text fields. To handle scrolling when the keyboard comes up, I use the scroll view to place my text fields. I use autorun.

Problem

I am struggling with an issue where extra space is added to the beginning of my scroll view at runtime. Like the insert for my scroll view, although I confirmed by registering that the inserts are zero.

In my implementation of viewDidLoad (), I do this to confirm the values โ€‹โ€‹...

UIEdgeInsets contentInsets = UIEdgeInsetsZero; self.scrollView.contentInset = contentInsets; self.scrollView.scrollIndicatorInsets = contentInsets; self.scrollView.contentSize = self.scrollView.bounds.size; self.scrollView.contentOffset = CGPointMake(0.0, 0.0); NSLog(@"Content Size: %fx %f", self.scrollView.contentSize.height, self.scrollView.contentSize.width); NSLog(@"Bounds Size: %fx %f", self.scrollView.bounds.size.height, self.scrollView.bounds.size.width); NSLog(@"Frame Size: %fx %f", self.scrollView.frame.size.height, self.scrollView.frame.size.width); NSLog(@"Inset Size top: %f bottom: %f", self.scrollView.contentInset.top, self.scrollView.contentInset.bottom); NSLog(@"Scroll Inset Size top: %f bottom: %f", self.scrollView.contentInset.top, self.scrollView.contentInset.bottom); 

Output:

 2013-10-08 11:38:42.953 test[6440:a0b] Content Size: 455.000000 x 320.000000 2013-10-08 11:38:42.954 test[6440:a0b] Bounds Size: 455.000000 x 320.000000 2013-10-08 11:38:42.955 test[6440:a0b] Frame Size: 455.000000 x 320.000000 2013-10-08 11:38:42.955 test[6440:a0b] Inset Size top: 0.000000 bottom: 0.000000 2013-10-08 11:38:42.956 test[6440:a0b] Scroll Inset Size top: 0.000000 bottom: 0.000000 

The space (insertion) added above my first text box seems to roughly correspond to the standard navigation headers, but this may be a coincidence.

In my scroll view, the height is set to 455 with a value of 64 so that it matches the navigation status bar and the tab bar at the bottom.

I have no messages about possible problems. The limitation of the upper and lower scroll spaces is positioned as 0 points (I suppose from the status columns and tabs.

When you start the application and view the extra space in the scroll, the scroll bars cover only the expected space (they do not include this extra space as part of the scrollable area).

Last remark. When I execute the keyboard notification logic. ( taken from an apple here ... ) The problem solves itself, no more space. What makes it look like a problem with initialization with what is configured in the storyboard?

Thank!

+14
objective-c autolayout ios7 uiscrollview storyboard
Oct 08 '13 at 16:08
source share
3 answers

UIViewControllers in iOS7 have an automaticallyAdjustsScrollViewInsets parameter. If it is YES , the scroll inserts will be automatically adjusted according to the height of the status bar, navigation bar and toolbar or tab bar.

This parameter can also be set in Interface Builder; it's called Customize Scroll in the Attributes Inspector.

Screenshothot

+60
Oct 08 '13 at 17:57
source share

In addition to disabling the โ€œCustom Scrollโ€ in the view controller in IB, as indicated by Greg, I found that another way to fix this problem was to change the โ€œTop Alignmentโ€ constraint that I had between the scroll view and the top guide layout. Changing the latter from the "Top Layout Guide.Bottom" to the "Top Layout Guide.Top" does everything right at run time, although you can still see the extra space in the storyboard (Xcode 6.4).

0
Sep 09 '15 at 4:30
source share

In the viewDidLoad method, this line of code is called:

 self.automaticallyAdjustsScrollViewInsets = false 
0
Dec 28 '16 at 11:18
source share



All Articles