1

我已经将我的 Xcode 更新到 4.5,我已经实现了如下的定位方法

  -(BOOL)shouldAutorotate{

    return YES;

  }

-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}

我在 willRotateToInterfaceOrientation 方法中设置按钮、标签、图像的框架大小

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{


  if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait )||
        ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown ))
  {

    // set frame sizes for portait

   }

  else if(( [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft )||
            ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight ))

  {

    // set frame sizes for landscape

   }

}

但有时旋转模拟器时不会调用此方法,有时模拟器在从另一个 viewController 导航时没有检测到方向。我检查了 info.plist 文件 - 很好。

4

2 回答 2

4

Apple 不会在 IOS 6.0 中调用 shouldAutorotatetoInterfaceOrientation 调用,除非您告诉主窗口将其发送到哪个视图控制器。

通过将 window.rootViewController 设置为我的应用程序的顶级视图控制器,我可以在我的应用程序中进行旋转

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   ...
   window.rootViewController = topLevelViewController;
   ...
}

我的应用程序的 iPhone 版本只支持两个纵向,所以我的顶级 iPhone 视图控制器需要一个新方法:

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

这是关于Buzz Touch的讨论。

于 2012-09-24T15:59:06.207 回答
0

Apple 已弃用 ios6 中的 shouldautorate 方法,改为使用这些方法

- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
// Returns interface orientation masks.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0);
于 2012-11-13T13:29:19.053 回答