要件を誤解しているかどうかはわかりませんが、これを設定方法を確認するための出発点になる可能性があります。
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect viewBounds = self.view.bounds;
CGRect scrollViewFrame = CGRectMake(0, 0, floorf(CGRectGetWidth(viewBounds) / 2.2), CGRectGetHeight(viewBounds));
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.center = self.view.center;
scrollView.contentSize = CGSizeMake(CGRectGetWidth(viewBounds) * 3, CGRectGetHeight(viewBounds) * 3);
scrollView.pagingEnabled = YES;
scrollView.clipsToBounds = NO;
UIPanGestureRecognizer *gestureRecognizer = scrollView.panGestureRecognizer;
[self.view addGestureRecognizer:gestureRecognizer];
for (int i = 0; i < 3; i++) {
CGRect frame = CGRectMake(10.f + (i * CGRectGetWidth(scrollView.bounds)), 10.f, CGRectGetWidth(scrollView.bounds) - 20.f, (CGRectGetHeight(scrollViewFrame) * 3) - 20.f);
UIView *view = [[UIView alloc] initWithFrame:frame];
view.backgroundColor = [UIColor redColor];
[scrollView addSubview:view];
}
[self.view addSubview:scrollView];
}
文字通り、これを空のviewControllerに入れるだけですviewDidLoad:
注意すべき重要事項は次のとおりです。
contentSize
すべてのパネルに十分な幅が必要です
clipsToBounds
NO
追加のビューを見ることができるようにする必要があります
- スクロールビューの境界は、基本的にメイン ビュー ポートです。
pagingEnabled
設定する必要があります
- スクロールビューから を取得し、代わりにそれを含むビューにアタッチ
panGestureRecognizer
して、含まれているビューの境界でパンが検出されるようにしました (これは大きい方です)。