デバイスが回転しているときに、ビューコントローラでイメージを非表示にしようとしています。私は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;
}
}
私は銃を飛ばしたように見えます。通知をwillRotateToInterfaceOrientationに移動してもまだダングが表示されています:duration: –
ああ、申し訳ありません。おそらくこれはうまくいくでしょう:UIDeviceはデバイスの向きを返します。必ずしもUIである必要はないので、 'UIDeviceOrientationFaceUp 'と' FaceDown'の値です。あなたのメソッドにブレークポイントを投げてください、それは返されているかもしれないし、あなたの条件を台無しにしているかもしれません。 – lxt
あなたは天才です! –