iOS 5 および iOS 6 を対象としたアプリを作成しましたが、何らかの理由で、iOS 6 を搭載したデバイスで使用した場合にのみ回転し、iPhone または iPad で回転し、iOS 5 を使用したデバイスでは回転しません。普遍的です。この問題を解決するのを手伝ってください! ありがとう
5 に答える
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
すべての uiviewcontroller サブクラスでこれら 2 つのメソッドをオーバーライドします。これは iOS 6 以前で機能します。
iOS5とiOS6は、異なる方向と回転のデリゲートを呼び出します。iOS 5では、以下を実装します。
shouldAutorotateToInterfaceOrientation:、これはiOS6で非推奨になりました。
したがって、iOS 6では、ルートビューコントローラーを設定し、以下を実装していることを確認してください。
shouldAutorotate:、supportedInterfaceOrientationsおよびsupportedInterfaceOrientationsForWindow:
同様の問題がありました。この質問の答えを確認できます:
要約すると、iOS 5 と iOS 6 で自動回転を完全に機能させ、PortraitUpsideDown の向きも処理するには、カスタムの UINavigationController を実装しself.window.rootViewController
て、アプリのデリゲートdidFinishLaunchingWithOptions
メソッドに割り当てる必要がありました。
shouldAutorotateToInterfaceOrientation は ios6 で廃止されました。
したがって、両方の OS バージョンでアプリを実行する場合は、次のように shouldAutorotateToInterfaceOrientation も追加します
//for ios6
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationLandscapeLeft ||orientation == UIInterfaceOrientationLandscapeRight )
{
return YES;
}
return NO;
}
//for ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//interfaceOrientation == UIInterfaceOrientationLandscapeRight;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
return YES;
}
return NO;
}
ios5 と ios6 の両方で自動回転をサポートするには、ios6 の場合にコールバックを提供する必要があります....`[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
そして、私たちは電話する必要があります
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutoRotate{
return YES;
}
iOS5用
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{ return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)); }