私は初心者なので、これがばかげた疑いである場合はご容赦ください...最近プロジェクトをxcode3からxcode4に変更しましたが、いくつかの問題があり、理由がわかりません...
スクロールビューのフレームとコンテンツ サイズ、および向きが変更された場合の変更を管理するには、次のようにします。
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
scrollView.frame = CGRectMake(0,0,480,300);
[scrollView setContentSize:CGSizeMake(480,560)];
}
else {
scrollView.frame = CGRectMake(0,0,320,460);
[scrollView setContentSize:CGSizeMake(320,560)];
}
[scrollView flashScrollIndicators];}
Xcode3では画面読み込み時にアプリがこのメソッドを呼び出すので、どのような状況でも問題なく動作していたと思います。
しかし、Xcode4 では、アプリは画面の読み込み時にこのメソッドを呼び出しません。向きが変わったときにのみ呼び出されます(この違いが存在する理由はわかりません)。そのため、画面が読み込まれるとスクロールビューが機能しません。デバイスの向きを変えると動き始めます。
次に、これを試しました:
- (void)viewDidLoad {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft ||
[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
scrollView.frame = CGRectMake(0,0,480,300);
[scrollView setContentSize:CGSizeMake(480,560)];
}
else {
scrollView.frame = CGRectMake(0,0,320,460);
[scrollView setContentSize:CGSizeMake(320,560)];
}
[scrollView flashScrollIndicators];
[super viewDidLoad];}
どうやら機能していたようですが...非常に奇妙なことが起こります...
別のビュー (縦向き) に移動し、向きを横向きに変更してから最初のビュー (横向き) に戻ると、ビューの自動サイズ変更マスクが狂ってしまいます。ビューの幅が実際よりも広いかのように、すべてのコンテンツが右側に移動します。また、コンテンツの一部にアクセスできません。しかし、向きを縦向きに変更すると、もう一度横向きにしても問題ありません。したがって、横方向の別のビューからビューに来るときだけ間違っています。
これは、ビューから別のビューに渡す方法です。
- (IBAction) btnUnVano:(id) sender {
PE2100UnVano *controller = [[PE2100UnVano alloc] initWithNibName:@"PE2100UnVano" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];}
私は何をすべきか?
Pd: 私の英語でごめんなさい
編集
OK、この部分は修正されました。willAnimateRotationToInterfaceOrientation を削除しましたが、これで正しく動作するようになりました:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Si la orientación es horizontal..
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft ||
[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
scrollView.frame = CGRectMake(0,0,480,300);
[scrollView setContentSize:CGSizeMake(480,560)];
}
// Si la orientación es vertical..
else {
scrollView.frame = CGRectMake(0,0,320,460);
[scrollView setContentSize:CGSizeMake(320,560)];
}
// Mostrar durante un instante los indicadores de scroll
[scrollView flashScrollIndicators];
// Retorna YES para soportar todas las orientaciones posibles
return YES;}
さて、別の問題があります。一部の画面では、次のコードで前の画面に戻ります。
- (IBAction) btnAtrasTabla:(id) sender {
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];}
この場合、オートサイズの問題が再び発生します。ポートレートでこの画面に移動し、ランドスケープに変更し、前の画面に戻ると、前の画面が間違ったオートサイズで表示されます。次に、方向を変更すると、すべてが再び正しくなります... 何かアイデアはありますか?