如何在旋转前检测iPhone方向 [英] how do I detect the iPhone orientation before rotating
问题描述
在我的程序中,我根据旋转移动的东西,但我不旋转整个视图。我正在使用:
In my program I'm moving things based on rotation, but I'm not rotating the entire view. I'm Using :
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]相对于与先前方向的差异进行更改。
This works as long as, when the program is launched, the device orientation is portrait, but not if the initial orientation is landscape or upside down, because [self doRotationStuff] makes changes relative to the difference from the previous orientation.
有一种方法可以在启动时或在设备旋转之前检测方向。
Is there a way to detect the orientation either at launch, or right before the device is rotated?
推荐答案
根据您的情况,更简单的选项可以是UIViewController类的interfaceOrientation属性。这在旋转之前是正确的。
Depending on your circumstances, a simpler option may be the interfaceOrientation property of the UIViewController class. This is correct before a rotation.
这篇关于如何在旋转前检测iPhone方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!