0

私のオブジェクトのinitメソッド

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didRotate:)
                                                    name:@"UIDeviceOrientationDidChangeNotification" 
                                                  object:nil];

回転メソッドを実行しました

- (void) didRotate:(NSNotification *)notification {

    NSLog(@"rotate notification");

    //MA_MobileAppDelegate *appDelegate = (MA_MobileAppDelegate *)[[UIApplication sharedApplication] delegate];

    //UIInterfaceOrientation orientation = appDelegate.tabBarController.interfaceOrientation;
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

何らかの理由で、didRotateは実際のローテーションの前に呼び出されたようです。したがって、現在/最終ローテーションを取得しようとすると、最後のローテーションを取得します。これが当てはまらないように思われるViewControllerは1つだけです。私が間違っていることについて何か考えはありますか?

4

2 に答える 2

1

コードを遅らせる必要がありました

[self performBlock:^(id sender) {

//rotation code

} afterDelay:0.1f];

UIApplicationにステータスバーの向きのプロパティを更新する時間を与えるために必要なのは、短い遅延だけです:(

于 2012-10-16T21:05:44.323 に答える
0

[[UIDevice currentDevice] orientation]iOSは、デバイスの向き( )とインターフェースの向き( )の2つの別々の向きを追跡します[[UIApplication sharedApplication] statusBarOrientation]。デバイスの向きを変更すると、インターフェイスの向きが変更される場合があります。システムがインターフェイスの向きを変更する前に、デバイスの向きの変更通知を受信して​​います。

観察してみてくださいUIApplicationDidChangeStatusBarOrientationNotification。によって投稿されました[UIApplication sharedApplication]

于 2012-10-16T21:04:53.933 に答える