ios 6中的定位问题 [英] Orientation issue in ios 6

查看:149
本文介绍了ios 6中的定位问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通用应用程序中工作,直到ios 5工作正常但在ios 6中存在方向问题。我的应用仅处于纵向模式。问题是当我的ipad处于横向模式时,而不是我启动我的应用程序而不是方向不会改变为protrait。所以请帮我一些代码,这样我强制我的应用程序只能在应用程序启动之前独立于设备的方向处于protrait模式

I am working in universal app which works fine till ios 5 but in ios 6 there is orientation problem. My app is only in portrait mode. The problem is when my ipad is in landscape mode and than if i start my app than the orientation does nt change to protrait. So please help me with some code so that i force my app to be in protrait mode only independent of the orientation of device before the app launches

推荐答案

这种情况正在发生,因为Apple已经改变了管理UIViewController方向的方法。在Ios6中,Oreintation处理不同。在iOS6容器(例如UINavigationController)中,不要咨询他们的孩子以确定他们是否应该自动旋转。默认情况下,应用程序和视图控制器支持的界面方向设置为iPad惯用语的UIInterfaceOrientationMaskAll和iPhone惯用语的UIInterfaceOrientationMaskAllButUpsideDown.So设备默认情况下更改方向。

This is happening because Apple Has changed the Way of managing the Orientation of UIViewController. In Ios6 Oreintation handles Differently .in iOS6 containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.So device getting orientation changed by default.

所以需要执行一些步骤。

So Need To Perform Some Steps.

1 - 从这里设置方向

2 -Place FirstController中的此代码添加到RootViewController

  @implementation UINavigationController (RotationIn_IOS6)
   //Here UINavigationController is the RootViewController added To the Window

 -(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}

 -(NSUInteger)supportedInterfaceOrientations
{
   return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
     return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end

**将以下方法放入ViewController,在IOS6中引入允许Oreintation更改**

** Put below methods in ViewController,Introduced In IOS6 Allow Oreintation Change**

  - (BOOL)shouldAutorotate
 {

   return NO;

  }

/*Return the Number of Oreintation going to supported in device*/

 - (NSUInteger)supportedInterfaceOrientations
  {
return  (UIInterfaceOrientationMaskPortrait |     UIInterfaceOrientationMaskPortraitUpsideDown );

 }

 // Returns interface orientation masks.

  - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  {
      return  (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown      ) ;

 }

这篇关于ios 6中的定位问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆