recently encountered a strange problem in the development process, after the status bar is hidden, the page TableView will automatically roll up 20 pixels.
The status is as follows:
This is because after the iOS7.0, the system automatically adjusts the layout and contentinsets of the ScrollView. This allows it to automatically adapt to the way that the entire screen can fit into the custom control after iOS7. Most of us do not want to receive the automatic impact of the system in the development process, but fully grasp every detail of the development process. There's one more thing to be willing to do because most of our applications are now going down to iOS6 and not providing such a feature in 6, so you still want to use relatively "conservative" code at the code level.
So the way to solve this problem is to talk about the system of these auto-tuning ScrollView contentinsest features shielded off. Here's how:
if ([[[[Uidevice Currentdevice] systemversion]compare:@ "7.0"]!=nsorderedascending) { Self.edgesforextendedlayout = Uirectedgenone; Self.extendedlayoutincludesopaquebars = NO; Self.modalpresentationcapturesstatusbarappearance = NO; Self.automaticallyadjustsscrollviewinsets=no; }
Where Edgesforextendedlayout represents the contentinsets that the ScrollView in this viewcontroller use to provide in the new features. We use None. The default is all, which means all directions are used.
Extendedlayoutincludesopaquebars Indicates whether this adaptive contentinsets includes the height of the statusbar. This is a more critical piece of code. The reason our tableview will scroll up 20 pixels is because when we hide the StatusBar and ScrollView think there is no status bar, its contentinsets.top automatically decreases by 20px.
Automaticallyadjustsscrollviewinsets Indicates whether the sub-view in the view.subviews of this viewcontroller is to be automatically adapted by the system. For example, if set to Yes (the default is also), then this tableView.contentInsets.top will be 64. Here we put no, there will be no automatic adjustment.
OK, let's run it again and get the following effect:
ok!
TableView automatic scrolling after hiding the status bar