2012-02-29 20 views
0

モーダルビュー表示で問題が発生しました。私の最初のビューはとてもよく回転します。モーダルビューのコントローラは "ShouldAutorotationToInterfaceRotation"メソッドを実装しますが、デバイスまたはシミュレータを回転させるとモーダルビューは回転しません。モーダルビューが回転しません

最初のビューでモーダルビューではなく回転イベントが検出されたかどうかを確認するためにコメントを追加しましたが、イベントを取得しません。

手掛かりがありますか?

答えて

1

モーダルビューの回転イベントを受け取るには、NSNotificationCenterを購読する必要があります。次に、モダール・ビューをボトム・ビューに対して正しい向きに保ちたい場合は、ビューを変換する方法があります。 orientationChanged

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

int initialOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 
if (initialOrientation == UIDeviceOrientationPortrait) 
    initialAngle = 0.0; 
else if (initialOrientation == UIDeviceOrientationLandscapeRight) 
    initialAngle = 90.0; 
else if (initialOrientation == UIDeviceOrientationPortraitUpsideDown) 
    initialAngle = 180.0; 
else if (initialOrientation == UIDeviceOrientationLandscapeLeft) 
    initialAngle = 270.0; 

currentAngle = initialAngle; 

次に機能を定義します:

のviewDidLoadでこれを入れて、角度として元の向きを保存します。ここでは一つの実施だ正しく相対回転するコードで(NSNotification *)通知を最初の方向に:

int newOrientation = [[notification object] orientation]; 
if (newOrientation == UIDeviceOrientationPortrait) 
    desiredAngle = 0.0; 
else if (newOrientation == UIDeviceOrientationLandscapeRight) 
    desiredAngle = 90.0; 
else if (newOrientation == UIDeviceOrientationPortraitUpsideDown) 
    desiredAngle = 180.0; 
else if (newOrientation == UIDeviceOrientationLandscapeLeft) 
    desiredAngle = 270.0; 

if(desiredAngle != currentAngle) 
{ 
    CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI * (-desiredAngle+initialAngle)/180.0);  
    CGAffineTransform translate = CGAffineTransformMakeTranslation(0, 0); 
    [[self releaseView] setTransform:CGAffineTransformConcat(translate, rotate)]; 
} 
currentAngle = desiredAngle; 
関連する問題