2011-11-14 23 views
0

私たちがiOSのオリエンテーションの変更に次の2つの方法を使用すると、違いはありますか?最初のケースでオリエンテーションの変更

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

-(void) orientationChange 
{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    NSLog(@"Orientation =%d",orientation); 
    NSLog(@"in Testtt"); 
} 

2通知センター使い方

1))のViewControllerオリエンテーションデリゲートメソッド

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    if(UIInterfaceOrientationLandscapeRight == interfaceOrientation || UIInterfaceOrientationLandscapeLeft == interfaceOrientation) 
     return YES; 
    else 
     return NO; 
} 

答えて

1

あなたはUIDeviceOrientationを受け取ることになります。 [[UIDevice currentDevice] orientation]は、UIDeviceOrientation、デバイスの方向を返します。しかし、UIDeviceOrientationは必ずしもUIInterfaceOrientationではないことに注意してください。たとえば、デバイスがプレーンテーブル上にある場合、予期しない値(UIDeviceOrientationUnknown)を受け取ることができます。

shouldAutorotateToInterfaceOrientationメソッドでは、インターフェイスの現在の向きであるUIInterfaceOrientationにアクセスできます。

関連する問題