Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios7 all searchviews and tableviews off by 20 pixels

EDIT: This is not an issue with the frame. The frame is in the correct spot. It is the content that is off. Yes, we are compensating for clear status bar. ViewDidLoad shows content offset is at 0,0.

On every page of my applcation that has a scrollview it's content is pushed down by 20 pixels. I think it may have something to do with the new StatusBar, or lack thereof. The bug also seems to be present in the simulators settings menu. Screenshot below. This only seems to affect the first scroll view that is added to a ViewController and only if no other views have been added to it. Table views are also being affected because they inherit from Scroll view. To be clear the scrollview starts at the correct origin but the content is pushed down by 20 pixels. This is bizarre because I would think if it was a status bar issue it would be 20 pixels above not below.

Currently we are fixing it by adding this to our base view controller

UIView *hackView = [[UIView alloc] init];
hackView.frame = CGRectMake(0, 0, 0, 0);
[self.view addSubview:hackView];

Obviously, this is a hack.

The same thing is happening on phone and in simulator even with the Gold Member version of IOS7 when building for latest IOS7. You can even see an example of the bug in the simulator's settings tableview and also in ours below.

enter image description here

IOS7 settings

This is a screenshot immediately after it loads. One bizarre thing that we noticed is that when we execute a pull to refresh it will correct the scrollview and rest at it's correct location. Alternatively, if we compensate it will look correct in the beginning but any subsequent pull to refreshes will migrate the scrollview to -20px

like image 594
Sean Dunford Avatar asked Sep 13 '13 22:09

Sean Dunford


3 Answers

After further testing in Xcode, my original workaround still works, but the real culprit seems to be a Navigation Controller combined with the Adjust Scroll View Insets flag on the view controller. Disabling that solved the issue.

[self setAutomaticallyAdjustsScrollViewInsets:NO];

Original workaround: Try reordering your view hierarchy or add an empty view at the top.

This happened to me, and it appears that when a UIScrollView or similar subclass is first in the hierarchy it gets offset by 20 pixels (to keep it from hitting the status bar). However, this still occurs even when the view in question is nowhere near the top.

This is reproducible in Interface Builder, and an easy workaround for me has been to reorder my views so that a label or button is first under the view controller's view. If that's not possible in your case, adding an empty view (even off screen) above your scrollview also seems to solve the problem.

like image 195
Nathan Rabe Avatar answered Sep 22 '22 11:09

Nathan Rabe


I added this to my UIViewControllers in viewDidLoad: which were affected and it fixed the issue for me:

NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"7.0" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending)
{
    // OS version >= 7.0
    self.edgesForExtendedLayout = UIRectEdgeNone;
}

Another, cleaner method:

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;
like image 36
RyanG Avatar answered Sep 21 '22 11:09

RyanG


How are you laying out your views? With autolayout you can use the topLayoutGuide, which should accommodate for these offsets.

like image 29
czechboy Avatar answered Sep 22 '22 11:09

czechboy