TableView automatic scrolling after hiding the status bar

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.