相关疑难解决方法(0)

如何在旋转前检测iPhone方向

在我的程序中,我根据旋转移动东西,但我不是在旋转整个视图.我正在使用 :

  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;

} 
Run Code Online (Sandbox Code Playgroud)

只要程序启动时,设备方向是纵向,但如果初始方向是横向或颠倒,则无效,因为[self doRotationStuff]相对于与前一个方向的差异进行更改.

有没有办法在发射时或在旋转设备之前检测方向?

iphone cocoa-touch objective-c iphone-sdk-3.0

12
推荐指数
2
解决办法
3万
查看次数

标签 统计

cocoa-touch ×1

iphone ×1

iphone-sdk-3.0 ×1

objective-c ×1