在我的程序中,我根据旋转移动物体,但我并没有旋转整个视图。我使用的是:
static UIDeviceOrientation previousOrientation = UIDeviceOrientationPortrait;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
- (void) didRotate:(NSNotification *)notification{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[self doRotationStuff:orientation: previousOrientation];
previousOrientation = orientation;
}
只要程序启动时设备方向为竖屏,这段代码就可以正常运行,但如果初始方向为横屏或倒置,则无法正常工作,因为[self doRotationStuff]会根据前一方向与当前方向的差异进行更改。是否有一种方法可以在启动时或旋转设备之前检测方向?