2

splitcontroller と、detailcontroller の viewdidload (ログイン画面) からモーダルに表示されるモーダルを備えたユニバーサル アプリがあります。

ipad 版を開くとき、デバイスの初期の向きに応じて、縦向きまたは横向きで起動できるようにしたいと考えています。問題は、常に縦向きで起動することです (ドキュメントによると予想されます)。

デバイスを縦向きにしてから横向きにすると、機能します。しかし、アプリを直接横向きに開いても、そうではありません。

ところで:私はすでにそのログインviewControllerに設定return trueしています(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

更新: viewDidLoad の代わりに viewDidAppear からセグエを実行すると、モーダルの向きは正しく機能しますが、SplitController がモーダルの前にしばらく表示されます。これを回避するにはどうすればよいですか?

- (void)viewDidAppear:(BOOL)animated
{
    [self.splitViewController performSegueWithIdentifier:@"toModal" sender:self.splitViewController];
}
4

1 に答える 1

1

の向きを(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation条件付きで設定できます。このようなものはきれいではありませんが、機能します:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if(orientation == 0) //Default orientation 
    //UI is in Default (Portrait) -- this is really a just a failsafe. 
else if(orientation == UIInterfaceOrientationPortrait)
    //Do something if the orientation is in Portrait
else if(orientation == UIInterfaceOrientationLandscapeLeft)
    // Do something if Left
else if(orientation == UIInterfaceOrientationLandscapeRight)
    //Do something if right

それ以外の場合、この投稿はあなたがやろうとしていることとかなり関連しているようです:

IPad の横向きでのアプリケーションの起動


提案2


以下を使用して、デバイスの向きを検出するメソッド (つまり、「deviceInfo」) を持つクラスを作成できます。

UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication]statusBarOrientation])

UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]statusBarOrientation])

必要なストレッチ係数/寸法/測定値を保存することもできます。次に、viewメソッド-(id)initWithFrame:(CGRect)frameを呼び出して方向を確認できます (つまりdeviceInfo.isLandscape?)。次に、あなたが に等しいと設定viewautoresizingMaskます UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth。次に、必要なディメンションに等しく-(void)layoutSubviews設定しview.frameます。

CGRectMake(x-origin, y-origin, width, height);

現在の向きを取得するためのリファレンスは次のとおりです。

http://www.ddeville.me/2011/01/getting-the-interface-orientation-in-ios/

ビュー フレームの寸法を変更するのは比較的簡単で、Apple のドキュメントや簡単なグーグル検索で見つけることができます。

于 2012-07-23T22:58:35.657 に答える