私は iOS 開発の初心者で、回転可能でサイズ変更可能なユーザー インターフェイスを実装しようとしています。私が遭遇している問題は、回転時に UI 要素の位置を再設定することです。以下の単純なコードを正しく動作させることさえできません。
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (BOOL)shouldAutorotate {
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
self.button.frame = CGRectMake(502.0, 207.0, 73.0, 44.0);
} else {
self.button.frame = CGRectMake(197.0, 69.0, 73.0, 44.0);
}
}
[サブビューの自動サイズ変更] オプションの選択を解除しました。ただし、ボタンは同じ場所に配置されます。正しい座標を持っているように見えるフレーム位置をログに記録しましたが、そのようにはなっていません。