0

我有一个 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];
}
4

1 回答 1

0

如果您从情节提要启动视图控制器,只需打开 Size Inspector 以检查根视图框架矩形的 x 是否设置为 0

于 2012-04-23T17:41:30.260 回答