Screen Adaptation Techniques for iOS6 and iOS7

Source: Internet
Author: User

1. No navigation controller or UITabBarController is packaged

1. When the Controller's view is UIScrollView \ UITableView \ UICollectionView (when the controller is UITableViewController)

-(Void) viewDidLoad

{

[Super viewDidLoad];

// # Ifdef _ IPHONE_7_0 indicates whether to run in Xcode5. The following code is available only in Xcode5.

# Ifdef _ IPHONE_7_0

If ([[UIDevice currentDevice]. systemVersion floatValue]> = 7.0 ){

Self. tableView. contentInset = UIEdgeInsetsMake (20, 0, 0, 0 );

}

# Endif

}

 

2. The Controller's view is a normal UIView, not a UIScrollView

# Ifdef _ IPHONE_7_0

-(Void) viewDidLayoutSubviews

{

// IOS7 & No packaged navigation Controller

If ([[UIDevice currentDevice]. systemVersion floatValue]> = 7.0 & self. navigationController = nil ){

CGFloat top = [self. topLayoutGuide length];

// Whether scrolling is supported

If ([self. view isKindOfClass: [UIScrollView class]) {

UIScrollView * scroll = (UIScrollView *) self. view;

Scroll. contentInset = UIEdgeInsetsMake (top, scroll. contentInset. left, scroll. contentInset. bottom, scroll. contentInset. right );

} Else {

CGRect bounds = self. view. bounds;

Bounds. origin. y =-top;

Self. view. bounds = bounds;

}

}

}

# Endif

 

Ii. Packaging of navigation controllers

1> the Controller's view is not UIScrollView

# Ifdef _ IPHONE_7_0

If ([[UIDevice currentDevice]. systemVersion floatValue]> = 7.0 ){

Self. edgesForExtendedLayout = UIRectEdgeNone;

}

# Endif

 

2> the Controller's view is UIScrollView.

No additional code adaptation required

 

Iii. Other cases (the above situations do not require a crash, as long as you master the following rules)

1. You want to move the view content down.

1> set bounds's y value in UIView

2> UIScrollView: Set the top value of contentInset.

 

2. Prevent the view of the sub-controller from being overwritten by the navigation bar or tabbar.

Self. edgesForExtendedLayout = UIRectEdgeNone;

 

Iv. Multi-controller nested processing

1. When multiple controllers are nested, the most reasonable solution is: UITabBarController nested UINavigationController

2. When the direct parent controller of UITableViewController is UINavigationController, no adaption code is required.

3. Other non-UITableViewController codes must be added.

# Ifdef _ IPHONE_7_0

If ([[UIDevice currentDevice]. systemVersion floatValue]> = 7.0 ){

Self. edgesForExtendedLayout = UIRectEdgeNone;

}

# Endif

Related Article

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.