ページングが有効になっている 3 つの uiviewcontrollers を含む uiscrollview があります。コンテンツ インセットが {0, 0, 0, 0} の場合、結果は次のようになります。
しかし、スクロールビューのコンテンツ インセットを左に -7 に変更すると、次のように修正されます。
-7 がこれを修正するためのマジック ナンバーである理由を理解しようとしています。SliderViewController のコードは次のとおりです。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil event:(Event*)event
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_event = event;
conversationVC = [[ConversationViewController alloc] initWithNibName:@"ConversationViewController" bundle:[NSBundle mainBundle] event:_event];
eventVC = [[EventControlViewController alloc] initWithNibName:@"EventControlViewController" bundle:[NSBundle mainBundle]];
suggestionVC = [[SuggestionViewController alloc] initWithNibName:@"SuggestionViewController" bundle:[NSBundle mainBundle]];
[self addChildViewController:conversationVC];
[self addChildViewController:eventVC];
[self addChildViewController:suggestionVC];
// Custom initialization
}
return self;
}
- (void)layoutSubviews
{
CGFloat curXLoc = 0;
CGFloat yMax = 0;
for(UIView *view in _scrollView.subviews)
{
CGRect frame = view.frame;
frame.origin.x = curXLoc;
view.frame = frame;
curXLoc += view.frame.size.width;
yMax = MAX(view.frame.size.height, yMax);
}
[_scrollView setContentSize:CGSizeMake(_scrollView.subviews.count * 320, yMax)];
}
- (void)viewDidLoad
{
[super viewDidLoad];
_scrollView.clipsToBounds = YES;
_scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[_scrollView addSubview:conversationVC.view];
[_scrollView addSubview:eventVC.view];
[_scrollView addSubview:suggestionVC.view];
[self layoutSubviews];
}