【发布时间】:2010-11-12 17:39:30
【问题描述】:
在我的程序中,我基于旋转来移动物体,但我并没有旋转整个视图。我正在使用:
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] 会相对于与先前方向的差异进行更改。
有没有办法在启动时或在设备旋转之前检测方向?
【问题讨论】:
标签: iphone objective-c cocoa-touch iphone-sdk-3.0