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] <span style="color:#3366ff;">bounds</span>]];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] <span style="color:#3366ff;">applicationFrame</span>]];
    
    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;
    }
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章