我有一个 uiscrollview,其中包含三个启用了分页的 uiviewcontroller。当 content inset 为 {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];
}