2011-09-25 14 views
0

デバイスが回転しているときに、ビューコントローラでイメージを非表示にしようとしています。私はbannerViewを担当する、PlayerViewControllerで通知を掲示していますし、アプリデリゲートでそれを聞いています:デバイスの回転でUIViewを非表示 - デバイスが水平のときには機能しません

- (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 
} 

すべてのアイデアは、なぜこの奇妙な動作が発生している:

ここで通知を送信するためのコードはありますか?

ちょうど1つのおしゃれな情報。デバイスが逆さまの向きにあるときに、シミュレータでの画像は、私が持っているにもかかわらず、示しています

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

答えて

0

はあなたのエラーは、あなたが通知を掲示しているときで起こっている可能性があります。

willAnimateRotationToInterfaceOrientationの前には、と呼ばれ、方向が変更されます(したがって、メソッド名では「will」)。だから私たちがポートレートからランドスケープに行くならば、現在のオリエンテーションはポートレートとして報告されるかもしれません(そうでないかもしれません)。

今、willAnimate...呼び出しはになるのオリエンテーションをtoInterfaceOrientationに返します。

willAnimate ...コールを受信したときに通知をトリガーし、[[UIDevice currentDevice]orientation]という通知コールでは、ポートレートはに戻ります。代わりに通知方法でオリエンテーションを要求する代わりに、willAnimateコールで提供されたオリエンテーションを渡す必要があります。

これが明確でない場合、ローテーションが変更される前にという1つの文のサマリー:が呼び出されます。

+0

私は銃を飛ばしたように見えます。通知をwillRotateToInterfaceOrientationに移動してもまだダングが表示されています:duration: –

+1

ああ、申し訳ありません。おそらくこれはうまくいくでしょう:UIDeviceはデバイスの向きを返します。必ずしもUIである必要はないので、 'UIDeviceOrientationFaceUp 'と' FaceDown'の値です。あなたのメソッドにブレークポイントを投げてください、それは返されているかもしれないし、あなたの条件を台無しにしているかもしれません。 – lxt

+0

あなたは天才です! –

関連する問題