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