最近在项目中遇到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的屏幕适配了,这里主要是竖屏,大多数程序也是竖屏
能够根据自身的须要进行修改。