2012-01-07 9 views
0

ストーリーボードモードで作成されたユニバーサルアプリケーションがあります。現在の方向に自動的に回転するように設定されています。 iPhoneモードでいくつかの向きを無効にしようとしましたが、シミュレータでテストすると機能しません。ストーリーボードのローテーションとオリエンテーションの問題

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    return ((interfaceOrientation != UIInterfaceOrientationLandscapeRight) || (interfaceOrientation != UIInterfaceOrientationLandscapeLeft)); 
} else { 
    return YES; 
} 
} 

また、iPadを回転させると、次のコードが表示されますが、黒い画面が表示されます。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
     self.view = landscape; 
     self.view.transform = CGAffineTransformMakeRotation(deg2rad*(90)); 
     self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0); 
    } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { 
     self.view = landscape; 
     self.view.transform = CGAffineTransformMakeRotation(deg2rad*(-90)); 
     self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0); 
    } else { 
     self.view = portrait; 
     self.view.transform = CGAffineTransformMakeRotation(0); 
     self.view.bounds = CGRectMake(0.0, 0.0, 768.0, 1004.0); 
    } 
} else { 

} 
} 

なぜこれらすべての問題が発生していますか?私はそれがうまく動作するストーリーボード広告なしで別のXcodeプロジェクトでコードを試してみました。何が起こっているのですか?これをどのように修正できますか?

答えて

3

2つの別々のスタックオーバーフローに関する質問を作成する必要があります。私はここであなたの最初の質問に答えます。

は、コードからこの行を考えてみましょう:向きが Rightある

return ((interfaceOrientation != UIInterfaceOrientationLandscapeRight) || (interfaceOrientation != UIInterfaceOrientationLandscapeLeft)); 
  • 場合は、あなたのコードは常にtrueを返す、return (Right != Right) || (Right != Left)に減少します。

  • 方向がLeftの場合、コードはreturn (Left != Right) || (Left != Left)に縮小され、常にtrueを返します。

  • 方向がUpの場合、コードはreturn (Up != Right) || (Up != Left)に縮小され、常にtrueを返します。

  • オリエンテーションがDownの場合、コードはreturn (Down != Right) || (Down != Left)に縮小され、常にtrueを返します。

許可する方向と除外する方向が明確ではありません。

return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
:あなたが唯一のランドスケープの向きを許可したい場合は、これを行う

return UIInterfaceOrientationIsPortrait(interfaceOrientation); 

:あなたが唯一の肖像画の向きを許可したい場合は、これを行います

関連する問題