iOS 6,5支持 portrait,landscape (橫豎屏的處理)

最近在項目中遇到iOS6的一點問題,主要是橫豎屏的處理不同了,多了一些方法,原來的方法被廢棄掉了。 html

可能主要是爲了適配iPhone5吧。具體的緣由不深究,解決問題。 app

在網上找了一些解決方法,可是不適合我在項目中使用。 post

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0) { spa

        [self.window addSubview:navController.view]; htm

    }else{ blog

        [self.window setRootViewController:navController]; get

    } it

有人建議這樣修改,可是我看不到任何這麼修改的依據,因此項目中並無使用這樣的方式修改, io

主要仍是依賴於SDK自身的特色來進行修改吧。 class

進入正題:

主要修改如下幾個方面

在AppDelegate中增添一個方法,我這裏只支持豎屏的處理,就只設置了這一種方式(能夠根據自身的須要進行設置)

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

    return (UIInterfaceOrientationMaskPortrait);

}

在viewController中增長下面的兩個方法,同時保留原有的方法

//iOS6中新增的兩個方法 

- (BOOL)shouldAutorotate

{

    return NO;

}

 

- (NSUInteger)supportedInterfaceOrientations

{

    return (UIInterfaceOrientationMaskPortrait);

}

//在iOS6中廢棄了的方法,保留,以適配iOS4和5 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{

    return toInterfaceOrientation == UIInterfaceOrientationPortrait;

}

 

搞定了,而後在項目中就能夠支持iOS6,iOS4和5的屏幕適配了,這裏主要是豎屏,大多數程序也是豎屏

能夠根據自身的須要進行修改。

相關文章
相關標籤/搜索