2

ここに私の問題があります:私のアプリには、ビューを切り替えることができるツールバーがあります。メインのもの、または少なくとも起動時のものは横向きモードで、他のビューに移動すると縦向きになります。問題は、最初のもの (横向き) に戻ろうとしたときに発生し、ビューが縦向きに表示されるため、すべてのビューが間違って表示されます。(それは多かれ少なかれ明確ですか? 乱雑に見える場合は申し訳ありません)。私がここに持っているいくつかのコード:

V1コントローラー:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

V2コントローラー:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(IBAction)goToV1 {
 V1Controller *v1 = [[V1Controller alloc] init];
 [self.view.superview addSubview:v1.view];
}

ビューを追加する前に、オブジェクト v1 で何かをすることはできますか? わかりません、あなたの助けが必要です。

解決された問題 ビューの遷移で、1 つの文が欠落していました。現在のビューをスーパービューから削除します。また、@Bradが言っていたこと。ありがとうございました。

-(IBAction)goToV1 {
     V1Controller *v1 = [[V1Controller alloc] init];
     [self.view.superview addSubview:v1.view];
     [self.view removeFromSuperview];
    }
4

1 に答える 1

4

あなたが言う時:

return (interfaceOrientation == UIInterfaceOrientationPortrait);

縦向きにのみ回転できるようにしています。

縦向きに回転してから横向きに戻したい場合は、"YES" を返します。

あなたが言うとき、同じ論理が適用されます

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);

あなたは効果的に言っています:「一方向に回転させてください - しかし、逆方向には決して戻さないでください」

于 2010-11-10T22:47:38.357 に答える