iOS ユニバーサル アプリで発生している問題を理解しようとしています。私は UIScrollView を持っており、そのページがデバイスの全寸法を占め、回転時にそれ自体を調整する必要があります。
私のviewDidLoadメソッドでは、次のようにテストしています:
NSArray *colors = [NSArray arrayWithObjects:[UIColor orangeColor], [UIColor cyanColor], [UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = _scrollView.bounds.size.width * i;
frame.origin.y = 0;
frame.size = _scrollView.bounds.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
[_scrollView addSubview:subview];
}
_scrollView.contentSize = CGSizeMake(_scrollView.bounds.size.width * colors.count, _scrollView.bounds.size.height);
次に、 didRotateFromInterfaceOrientationメソッドに追加しました。
_scrollView.contentSize = CGSizeMake(_scrollView.bounds.size.width * colors.count, _scrollView.bounds.size.height);
for (int i= 0; i< colors.count; i++)
{
CGRect frame;
frame.origin.x = _scrollView.bounds.size.width * i;
frame.origin.y = 0;
frame.size = _scrollView.bounds.size;
UIView *subview= [[_scrollView subviews] objectAtIndex:i];
subview.frame= frame;
}
これは機能しているようですが、デバイスの回転中にメインビューにクリッピングがあるようです。
回転時に何が起こるかのスクリーンショットを次に示します。
回転させた後にサイズを変えたせいだと思って、willRotateToInterfaceOrientationメソッドで処理しようとしたのですが、間違った結果になってしまいました…
- これを間違って処理していますか?
- 正しいアプローチは何でしょうか?
ティア!S.
これを間違って処理していますか?