問題描述
我正在嘗試實現一個可滾動的自定義標簽欄,并且在每個標簽欄項目上都有分頁.為此,我正在使用委托 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 的邊緣工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!