0

デバイスを回転させたときに、ViewControllerで画像を非表示にしようとしています。PlayerViewControllerに通知を投稿し、bannerViewを担当するアプリデリゲートで通知をリッスンしています。

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

  UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if ((orientation == UIDeviceOrientationLandscapeLeft) ||
    (orientation == UIDeviceOrientationLandscapeRight)) {

    bannerView.hidden = ([[self.navigationController visibleViewController] isKindOfClass:[PlayerViewController class]]) ? YES : NO;

} else {
    bannerView.hidden = NO;
}
}

PlayerViewControllerは通知を送信し、アプリデリゲートはbannerViewを非表示にします。ただし、デバイスをテーブルに平らに置くと、画像が表示されます。デバイスが垂直に保持されているが水平に画像が表示される場合は正常に動作します...奇妙です。

通知を送信するコードは次のとおりです。

 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                     duration:(NSTimeInterval)duration {

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
 ... hide other stuff in this view controller
 }

この奇妙な振る舞いが発生している理由はありますか?

ほんの一口より多くの情報。シミュレーターでは、次のような場合でも、デバイスが逆さまになっているときの画像が表示されます。

- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
 {
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationPortrait) {
    return YES;
} else {
    return NO;
}
}
4

1 に答える 1

0

通知を投稿しているときにエラーが発生している可能性があります。

willAnimateRotationToInterfaceOrientation向きの変更が行われる前に呼び出されます (したがって、メソッド名に「will」が含まれています)。そのため、縦向きから横向きに変更した場合でも、現在の向きが縦向きとして報告されることがあります (そうでない場合もありますが、場合によって異なります)。

今、willAnimate...呼び出しは- 発生しようtoInterfaceOrientationとしているオリエンテーションを返します。

... 呼び出しを受け取ったときに通知をトリガーし、willAnimateその通知呼び出しの中で[[UIDevice currentDevice]orientation]:を返します Portrait。通知メソッドでオリエンテーションをリクエストする代わりに、willAnimate呼び出しで提供されたオリエンテーションを渡す必要があります。

それが明確でない場合は、次の 1 つの文の要約:willAnimateRotationToInterfaceOrientationが呼び出されてから回転が変更されます。

于 2011-09-26T00:09:07.107 に答える