gpt4 book ai didi

ios - UIScrollview 不滚动 iOS

转载 作者:行者123 更新时间:2023-11-28 20:09:56 26 4
gpt4 key购买 nike

我在一个水平滚动的 View 中创建多个 ScrollView 。以下代码工作正常:

-(void)updateSection {
builder = [NSMutableArray array];
float xPosition = 0;
float xposbut = 100;

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100, self.frame.size.width, self.frame.size.height - 69)];

scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.delegate = self;
[self addSubview:scrollView];

for (int i = 1; i < itemArticleArray.count; i++) {
ItemView *item = [ItemView loadNibs];
item.frame = CGRectMake(xposbut, 10, item.frame.size.width, item.frame.size.height);

xPosition += scrollView.frame.size.width + 2;
xposbut += 500;
UIView *seperatorView = [[UIView alloc] initWithFrame:CGRectMake(xposbut - 50, 4, 2, scrollView.frame.size.height - 8)];
[scrollView addSubview:seperatorView];
xPosition += scrollView.frame.size.width + 4;

[scrollView addSubview: item];
[builder addObject:item];
}

[scrollView setContentSize:CGSizeMake(xposbut, scrollView.frame.size.height)];
[self addSubview:scrollView];
}

但是,当我将第 8 行代码更改为以下内容时:

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 400, self.frame.size.width, self.frame.size.height - 69)];

它使布局看起来不错,但 ScrollView 根本不滚动。有什么想法吗?

最佳答案

您将 contentSize.height 设置为 scrollView.frame.size.height,因此 scrollView 无法滚动。您必须将 contentSize 设置为 scrollView 的总高度,包括不可见区域。框架只是屏幕上的区域。

关于ios - UIScrollview 不滚动 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20705533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com