我正在尝试实现一个可滚动的自定义标签栏,并且在每个标签栏项目上都有分页.为此,我正在使用委托 scrollViewWillEndDragging:withVelocity:targetContentOffset: 它完美地解决了一个问题.
I'm trying to implement a custom tab bar which is scrollable and has paging at each tab bar item. For that i'm using the delegate scrollViewWillEndDragging:withVelocity:targetContentOffset: which works perfectly with one problem.
我的分页工作方式是,如果 contentOffset 靠近正确的项目,则 targetContentOffset 会更改为该项目的偏移量.左侧也一样.
The way my paging works is, if the contentOffset is near the right item, it the targetContentOffset changes to the offset of that item. Same thing for the left side.
问题是,每当我在第一个项目的左半部分和最后一个项目的右侧(滚动视图水平工作)时,它应该转到 ContentOffset 0 和最右边项目的内容偏移量(减去屏幕上的那些),但它没有.
The problem is, whenever I'm at at the left half of the first item and the right of the last (the scroll view works horizontally) it's supposed to go to ContentOffset 0 and the content offset of the rightmost item (minus the ones on screen), but it doesn't.
我检查了调试器,targetContentOffset->x 确实为 0(在第一种情况下 - 最左边的项目的左侧).所以问题是 UIScrollView 没有在那里滚动.我迷路了.
I checked with the debugger and the targetContentOffset->x is indeed 0 (in the first case - left of the leftmost item). So the problem is the UIScrollView not scrolling there. I'm lost.
这是我实现的委托:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset{
NSInteger index = lrintf(targetContentOffset->x/self.tabWidth);
targetContentOffset->x = index * self.tabWidth;
}
这是解释我想要做什么的图表.
Here is the diagram explaining what i want to do.
|-------|-------|-------|-------|-------|-------|-------|
| | | | | | | |
| | | | | | | |
|_______|_______|_______|_______|_______|_______|_______|
|_______________________________________|
where it is and i scroll it to the left
<----|
|_______________________________________|
where it would stop
|_______________________________________|
where i want it to stop
这似乎是一个已知问题.经过一番调查并与其他人交谈后,有人建议这可能是一个错误,结果证明是正确的.我向 Apple 报告了它,它是否被标记为重复但仍处于打开状态.只为遇到同样问题的人解答.我像 Big Papoo 建议的那样解决它,通过使用接近我想要的偏移量(0.1 似乎可以做到).右端也一样.
This is a known issue it seems. After some investigation and talking to other people it was suggested it could be a bug, which turned out to be correct. I reported it to Apple and was it marked as duplicate but is still open. Just answering for those of you with the same problem. I workaround it like Big Papoo suggests, by using an offset close to what I want (0.1 seems to do it). The same for the right end.
这篇关于scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!