iOS 6 中的界面方向检查



可能的重复项:
iOS 6应该自动旋转:未被调用

我需要一种方法来知道用户何时更改方向...

我试过了

-(BOOL) shouldAutorotate { //never called
UIInterfaceOrientation toInterfaceOrientation = [[UIDevice currentDevice] orientation];
if(toInterfaceOrientation == UIInterfaceOrientationPortrait)
    //a code here
return YES;
}

我如何知道用户何时更改 iPad 的方向?

请记住在info.plist中设置支持的方向。

尝试使用

  - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
  - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

(在 iOS 6.0 中已弃用)

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;

确保你先调用它:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

然后在此处跟踪方向更改:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    //your code here 
}

这里的持续时间很重要,因为这是完成方向更改所需的时间。只有此时,新的方向才会完全确定

最新更新