實現了一個UIViewController的Category.
//
// UIViewController+Adaptive.h
// TestIOS7
//
// Created by skychi on 14-1-14.
// Copyright (c) 2014年 skychi. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (Adaptive)
-(void)extendEdgesLayout;
-(void)resetViewBounds;
@end
//
// UIViewController+Adaptive.m
// TestIOS7
//
// Created by skychi on 14-1-14.
// Copyright (c) 2014年 skychi. All rights reserved.
//
#import "UIViewController+Adaptive.h"
@implementation UIViewController (Adaptive)
-(void)extendEdgesLayout{
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
self.edgesForExtendedLayout = UIRectEdgeNone ;
}
-(void)resetViewBounds{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
self.view.bounds = CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height);
}
}
@end
1.去掉Use AutoLayout.
2.在-(void)viewWillAppear:(BOOL)animated 中調用.
UINavigationBar存在時, 調用-(void)extendEdgesLayout;
UINavigationBar不存在時, 調用-(void)resetViewBounds;
UINavigationBar存在且隱藏時, 同時調用上述來兩個方法.
PS:有點Bug.如果UINavigationController存在且隱藏,並且子View爲UITableView時,UITableView的ContentSize高度小了大約20.待修正.