问题描述
我有一个奇怪的问题setContentOffset,我似乎无法解决:
我试图建立一个无尽的滚动视图,所以我想重置内容偏移量一定位置。
下面的代码setContentOffset将被调用x = 160px。
如果我拖动滚动视图,我的日志如下所示:
I have a weird issue with setContentOffset which I don't seem to be able to solve:I'm trying to build an "endless" scroll view, so I'd like to reset the content offset at a certain position.With the code below setContentOffset will be called at x=160px.If I drag the scroll view my log looks like this:
offset:158
offset: 158
:159
补偿:160
补偿:80
offset:160
offset: 160
会发生什么是我的setContentOffset(到80)被执行,当我继续拖动
UIScrollView似乎已经忘记了并继续在160.
甚至weirder:当我设置动画:YES它的工作。也许是时间问题?
当我在scrollViewDidScroll中调用setContentOffset时,会再次调用scrollViewDidScroll。
What happens is that my setContentOffset (to 80) is performed, when I keep on draggingUIScrollView seem to have forgotten about it and continues at 160.Even weirder: When I set animated:YES it works. Maybe a timing issue?When I call setContentOffset from within scrollViewDidScroll, scrollViewDidScroll will be called again.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSInteger tileNo = floor(scrollView.contentOffset.x / 80);
NSLog(@"offset: %f, tile: %d, lastTile: %d", scrollView.contentOffset.x, tileNo, lastTileNo);
if (tileNo > lastTileNo) {
[scrollView setContentOffset:CGPointMake(80, 0) animated:NO];
}
lastTileNo = tileNo;
}
,
Stephan
Thanks for helping me out, Stephan
推荐答案
刚从苹果的sombody得到这个答案:这是一个已知问题,在未来的iPhone SDK的版本中,如果你能够测试它,你应该实际上发现它是固定的当前测试版,如果你仍然有麻烦,请提交一个新的错误。
Just got this answer from sombody at Apple: "This is a known issue and will be fixed in a future release of the iPhone SDK. If you're able to test it, you should actually find it's fixed in the current beta. If you're still having trouble with that please file a new bug."
这篇关于iPhone UIScrollView / setContentOffset怪异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!