1

This is my understanding about UIScrollView (iOS 7):

  • contentOffset defines the point of origin of the content view
  • contentInset effectively can add "padding" around the content view

In Xcode, I created a single-view application. In IB, I added a UIScrollView to the view controller, and embedded the controller in a navigation controller. In the view controller code, I added the following method:

- (void)viewDidAppear:(BOOL)animated
{
    [self.scrollView setContentSize:CGSizeMake(380, 1000)];
    NSLog(@"top = %f, bounds top %f", self.scrollView.frame.origin.y, self.scrollView.bounds.origin.y);
    NSLog(@"offset y = %f", self.scrollView.contentOffset.y);
    NSLog(@"height = %f", self.scrollView.contentSize.height);
    NSLog(@"inset top = %f", self.scrollView.contentInset.top);
    NSLog(@"inset bottom = %f", self.scrollView.contentInset.bottom);
}

My results:

top = 0.000000, bounds top -64.000000
offset y = -64.000000
height = 1000.000000
top = 64.000000
bottom = 0.000000

The contentInset.top value effectively moves the content down so it is below the navigation bar. Why is contentOffset.y being set to -64, and the bounds of the scroll view being set to -64?

Thanks in advance

KlimczakM
  • 12,576
  • 11
  • 64
  • 83
applegal
  • 25
  • 1
  • 5
  • I am unable to reproduce this issue. Are you doing `[self.scrollView setContentOffset:CGPointMake(0, -64)];` or something that might do this? – staticVoidMan May 02 '14 at 19:29
  • Thanks for checking this out. I didn't add in the setContentOffset. Also, if I remove the view controller from the navigation controller, I get zeros for the bounds top, offset y, and top values listed in my results. – applegal May 02 '14 at 19:45
  • which xcode version? (_just asking_) – staticVoidMan May 02 '14 at 19:46
  • I'm using 5.1.1. I also tried building a new app, and am getting the same results. – applegal May 02 '14 at 19:49
  • hm... share the project and i'll take a look. – staticVoidMan May 02 '14 at 20:30
  • Thanks, I appreciate it but I really can’t send out any projects. Actually, I’m more concerned with how contentInset, contentOffset, and UIScrollView work together. – applegal May 02 '14 at 20:43
  • i understand but honestly... i thought you said you "tried building a new app" which, imho, means a small project that reproduces this scenario and this scenario alone. – staticVoidMan May 02 '14 at 20:47
  • I did build a new app as I described (twice, actually). Please accept my apology, but I really can't send out any projects. Thanks again for your time, but I'm going to do more research. – applegal May 02 '14 at 21:05
  • np. hope you find the issue soon – staticVoidMan May 03 '14 at 09:20
  • Translucent navigation bar to blame? – atulkhatri May 23 '16 at 11:05

1 Answers1

1

Because the automaticallyAdjustsScrollViewInsets default value is YES in iOS 7.0.

The default value of this property is YES, which lets container view controllers know that they should adjust the scroll view insets of this view controller’s view to account for screen areas consumed by a status bar, search bar, navigation bar, toolbar, or tab bar. Set this property to NO if your view controller implementation manages its own scroll view inset adjustments.

UIViewController Class Reference

Lei Kan
  • 487
  • 7
  • 20