ExtendedLayout and UIViewController of the uiviewcontroller Series

Source: Internet
Author: User

ExtendedLayout and UIViewController of the uiviewcontroller Series

References:

Http://stackoverflow.com/questions/18798792/explaining-difference-between-automaticallyadjustsscrollviewinsets-extendedlayo

Http://redth.codes/ios7-full-screen-layout/

 

After iOS 7, a series of attributes are introduced in ViewController to manage the page layout.

 

The following is the official documentation provided by Apple. After reading this article, I still think it is too abstract. So I will use the code to experiment.

edgesForExtendedLayout 

The extended edges to use for the layout.

automaticallyAdjustsScrollViewInsets 

A Boolean value that indicates whether the view controller shoshould automatically adjust its scroll view insets.

extendedLayoutIncludesOpaqueBars 

A Boolean value indicating whether or not the extended layout provided des opaque bars. EdgesForExtendedLayoutCreate a project for a single page, and add UINavigationController to set the background to Red. The interface effect is as follows: therefore, after iOS7, the View layout is full screen by default, by default, the Navigation Bar is translucent, so the red background is displayed under the Navigation Bar.
- (void)viewDidLoad {    [super viewDidLoad];    self.edgesForExtendedLayout = UIRectEdgeNone;}

Set edgesForExtendedLayoutUIRectEdgeNone, Indicating that the View is not extended to the entire screen. The page effect is as follows:

 

UIRectEdge is an enumeration type. It is easy to understand other values by literal meaning.

typedef enum : NSUInteger {   UIRectEdgeNone   = 0,   UIRectEdgeTop    = 1 << 0,   UIRectEdgeLeft   = 1 << 1,   UIRectEdgeBottom = 1 << 2,   UIRectEdgeRight  = 1 << 3,   UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight } UIRectEdge;

 

automaticallyAdjustsScrollViewInsets 

This attribute is used if the page is ScrollView or UITableView, we usually want the content of ScrollView or UITableView to be displayed under UINavigation Bar.

Set edgesForExtendedLayout = UIRectEdgeNone or self. navigationController. navigationBar. translucent = NO; enables the view layout to start under the UINavigation Bar. However, when the page slides, the view cannot occupy full screen.

AutomaticallyAdjustsScrollViewInsets can meet this requirement well.

self.automaticallyAdjustsScrollViewInsets = NO;

UITableView is blocked by UINavigation Bar.

 

self.automaticallyAdjustsScrollViewInsets = YES;

At this time, we can see that the UITableView content starts under the UINavigation Bar, and the View on this page still occupies the whole screen, so this attribute is completely done!

 

ExtendedLayoutIncludesOpaqueBars

If the status bar is not transparent, the page layout does not contain the status bar by default, unless you set this attribute to YES. Therefore, if your page is extended to the Navigation Bar (edgesForExtendedLayout = UIRectEdgeAll), if this attribute is set to NO (default), if the status Bar is not transparent, the page will not be extended to the status Bar.

 

Please refer to the following link for more information: http://redth.codes/ios7 full-screen-layout /.AutomaticallyAdjustsScrollViewInsets does not help us to calculate the Inset of ScrollView/TableView normally. At this time, we will set it by ourselves.

self.myTableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);

 

 

 

 

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.