scrollViewWillEndDragging:withVelocity:targetContentOffset:不在UISCrollView的边缘上工作 [英] scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView

查看:1911
本文介绍了scrollViewWillEndDragging:withVelocity:targetContentOffset:不在UISCrollView的边缘上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个可滚动的自定义标签栏,并在每个标签栏项目上进行分页。为此我正在使用委托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靠近右边item,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


推荐答案

这个似乎是一个众所周知的问题。经过一些调查并与其他人交谈后,有人认为这可能是一个错误,结果证明是正确的。我向苹果公司报告过,它被标记为重复但仍然是开放的。只是回答那些有同样问题的人。我像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的边缘上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆