可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm developing my app to work with iOS7.
I have a UINavigationController I'm pushing a UIViewController that has a ScrollView inside it. Inside the scrollView I have a tableView.
Is it possible to achieve that when I scroll the tableView inside the scrollView the list will appear behind that Status bar. Same why it would be if I had a UINavigationController and a UIViewController with a tableView in it.
So this it the hierarchy :
UINavigationController
-> UIViewController
-> UIScrollView
-> UITableView
.
and I want that when a user scroll the table,the cells in the top will be visible under the status bar.
If there is no UIScrollView
it happens automatically in iOS7.
Thanks.
回答1:
Just set automaticallyAdjustsScrollViewInsets
to NO
in the viewController init method.
In Storyboard, you can switch the property directly in the property panel when the UIViewController is selected.
If you use xib, just set it like this:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self.automaticallyAdjustsScrollViewInsets = NO;
}
Note: this is right since iOS7 and still in iOS8.
回答2:
none of the above workd for me, until I noticed that I had to set Content Insets from Automatically to Never in the interfacebuilder:
回答3:
Starting with iOS 11 you can use this new property with a fallback (Swift 4):
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
}
else
{
self.automaticallyAdjustsScrollViewInsets = false
}
回答4:
Thats just dumb from Apple. One more weird behaviour to worry about. Anyhow, I ended up setting the scroll view content inset for top to -20 (from IB).
回答5:
I found the solution! Just set:
self.automaticallyAdjustsScrollViewInsets = false
on the view controller that has the UIScrollView.
回答6:
You probably has seen this recommendation a thousand times but, check the 'The Status Bar' section on the iOS 7 transition guide(can't post the direct link here).
Blunt resuming, on ios7 the status bar is part of the view. This means that almost anything you put on your view, will be under the bar, unless you say the contrary. A work around i found for that problem was making the status bar opaque.
Another way could be disabling the status bar on that specific view. Like on this thread.
回答7:
I have had a similar sort of problem, and I found that to ensure my scrollview content doesn't go under the status bar, I applied a setContentInset
.
So in your situation, if you are using an inset, I would use suggest using UIScrollViewDelegate
or scrollViewDidScroll
tailored to your tableview. If a scroll is occurring, disregard the scrollview inset.
回答8:
don't hide the statusBar, the scrollView won't jump