0

我的应用程序在滚动视图上动态生成项目。由于滚动视图没有确定的高度,因此它会在某个条件后不断增加其高度。但是,我只能在屏幕上放置 12 个项目,所以我希望它在items%12==0;. 经过一番研究,我了解了 contentOffset。但是,我没有得到我想要的行为,它一直滚动到顶部并冻结,直到我在屏幕上再添加 12 个项目。这是我的条件。

if (itemsLength %2 ==0) {

xPos = 20;
yPos += 60;
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width,scrollViewHeight+=50)];
NSLog(@"%i",scrollViewHeight);


}
if (itemsLength %12 == 0) {

CGPoint bottomOffset = CGPointMake(0,self.scrollView.contentSize.height -  self.scrollView.bounds.size.height);
[scrollView setContentOffset:bottomOffset animated:YES];


}

谢谢!~地毯嘶嘶声

编辑:有没有办法滚动到我的 Scrollview 中的某个点,而不更改内容偏移量?这样做会破坏我的其余代码。

4

1 回答 1

1

尝试这个

if (itemsLength %12 == 0) {

[scrollView scrollRectToVisible:CGRectMake(0,scrollViewHeight-50,320,50) animated:YES];

}
于 2013-05-26T16:35:37.277 回答