iOS7之后视图被导航栏遮挡问题

在开发iOS7的界面的时候,有时候你会发现UIViewController里的subView有时会被导航栏遮盖,原因是iOS7鼓励全屏布局,UIViewController中的self.view的坐标原点是从导航栏的原点开始算起。

解决办法:

方法1.设置self.window的frame时用applicationFrame 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
//    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        GuideViewController *guideViewController = [[GuideViewController alloc] init];
        _window.rootViewController = guideViewController;
        [_window makeKeyAndVisible];
    }
    else
    {
        // 首次进入判断是否已登录
        // 1.未登录进入注册界面
        // 2.已登录进入主界面
        if (/* DISABLES CODE */ (1))
        {
            RegistViewController *registVC = [[RegistViewController alloc] init];
            self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:registVC];
            
            [self.window makeKeyAndVisible];
        }
        else
        {
            [self openMain];
        }
    }
    
    return YES;
}

方法2.在viewDidLoad里面加上下面的方法

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    if( ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.0))
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
    }
}



你可能感兴趣的:(iOS7之后视图被导航栏遮挡问题)