2

多くの投稿を読んだ後、私はまだこの問題を解決する方法の手がかりを持っていません...

私のアプリの最初のビューはtableViewControllerです。オーバーライドします

(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 

そしてそれは常にYESを返します。

iPadを横向きで直立させた場合、アプリを起動した直後にiPadが回転します。ただし、iPadをテーブルの上に平らに置くと、ホームページが横向きであっても、縦向きで起動します。

問題は、ホームページの向きを取得して、その向きでアプリを起動するにはどうすればよいかということだと思います。

4

4 に答える 4

1

私のアプリはopenGLですが、これを処理する方法は通知を使用することでした:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

// This is called right BEFORE the view is about to rotate. Here I'm using a notification message
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
        NSNotification* notification = [NSNotification notificationWithName:@"orientationIsPortrait" object:self];
        [[NSNotificationCenter defaultCenter] postNotification:notification];
    }
    else {
        NSNotification* notification = [NSNotification notificationWithName:@"orientationIsLandscape" object:self];
        [[NSNotificationCenter defaultCenter] postNotification:notification];
    }

}

willRotateToInterfaceOrientation は、実際に向きの回転を開始する直前に呼び出されます。

次に、EAGLView initWithFrame: オブザーバーを設定します。

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewBecamePortrait:) name:@"orientationIsPortrait" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewBecameLandscape:) name:@"orientationIsLandscape" object:nil];

viewBecamePortrait と viewBecameLandscape では、変更をプログラムで処理します。

于 2010-07-14T17:02:26.010 に答える
1

私はこれと同じ問題を抱えていました。ウィンドウに追加する最初のView Controllerと、その向きに関係なく、いくつかのファンキーなものがあります。最初のビュー コントローラーを正しい向きで開きたい場合は、すべてのビュー コントローラーが向きに対して YES を返すことを確認してください。

于 2010-07-02T21:26:00.660 に答える
0

次のように、ステータスバーの向きを使用してopenglviewの向きを合わせました。

UIDeviceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;       
NSLog(@"%s: orientation: %i", _cmd, (int)orientation); 
于 2010-12-28T12:13:55.503 に答える
0

アプリケーションの開始時に willRotateToInterfaceOrientation は、「ホーム」画面が横向きモードの場合にのみ使用されます。このようにして、デバイスが「上向き」または「下向き」のときに方向を検出できます。[UIDevice currentDevice].orientation は、デバイスが地面と平行でない場合に機能します。

于 2010-11-26T15:06:15.430 に答える