没有调用scrollViewDidEndDecelerating
我有一个包含大图像的 UIScrollView,并使用分页在图像之间滚动。为了节省内存,我只加载当前可见图像之前和之后的一张图像,并在滚动完成后加载/释放新图像。当快速滚动并且未调用scrollViewDidEndDecelerating 时,就会出现此问题。 当调用scrollViewDidEndDecelerating时,我想在活动页面中显示图像名称。
我该如何解决这个问题?为什么会出现这种情况?
I have a UIScrollView that contains large images and am using paging to scroll between images. In order to save memory, I am loading only one image before and after the currently visible one and loading/releasing new images after a scroll has completed. The problem occurs when one scrolls quickly and scrollViewDidEndDecelerating is not called.
When the scrollViewDidEndDecelerating is called I wanted to display the image name in the active page.
How do I solve this? Why does this happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
scrollViewDidEndDragging 将在每次滚动完成后调用
scrollViewDidEndDecelerating 不要在每次拖动时调用(如果拖动停止后不以加速速度拖动,则永远不会调用此函数) strong>
scrollViewDidEndScrollingAnimation 如果您想使用 api 移动滚动视图而不是拖动,则会调用此 api。
scrollViewDidEndDragging will call after each scroll complete
scrollViewDidEndDecelerating don't call in each drag (if you don't drag with acce speed after draged stop it will don't never call this func)
scrollViewDidEndScrollingAnimation if you want move the scroll view use api not with drag, this api will called.
我用滚动视图做同样的事情——延迟加载图像。实际上,我们必须加载一个拉伸的缩略图(制作图像的模糊低分辨率版本),然后在页面实际 100% 显示在视图中时加载真实图像。
我要做的就是在scrollViewDidScroll:scrollView 中使用以下代码。
上面计算了将要显示的页面(当您滚动时)。当页面浏览量显示到 50% 时,它实际上会更改当前页码。这可以与页面控件结合使用以突出显示当前页面点。
使用上面的内容,(在滚动视图上启用分页)当用户使用手指更改页面(正常行为)时,当页面 100% 显示时,将调用scrollViewDidEndDecelerating:scrollView。我所说的 100% 是指您只能看到一页,而不能看到另一页的一部分。
但是我们在滚动视图的末尾有一个“重新开始”按钮,它调用我的scrollToPage:函数。
使用scrollRectToVisible:animated:方法不会触发scrollViewDidEndDecelerating:方法,所以我只是添加了对这两个方法的sharpen方法(它只是在图像视图中加载高分辨率图像)调用,这样如果用户滚动或者如果按下重新开始按钮。
我希望这有帮助!
Im doing the same thing with a scroll view - lazy loading of images. We actually had to load a thumbnail that is stretched (making a blurry low res version of the image) and then load the real image when the page is actually being displayed 100% in view.
What I had to do was use the following code in the scrollViewDidScroll:scrollView.
The above calculates the page that is going to be displayed (as your scrolling). It will actually change the current page number when the page view is 50% displayed. This can be used in conjunction with the page control to highlight the current page dot.
Using the above, (with paging enabled on the scroll view) when the user uses their finger to change the page (the normal behavior) scrollViewDidEndDecelerating:scrollView is called when the page is 100% displayed. By 100% I mean you can only see one page not part of one part of another.
But we have a 'Start Over' button at the end of the scroll view that calls my scrollToPage: function.
Using scrollRectToVisible:animated: method does not trigger the scrollViewDidEndDecelerating: method so I simply added the sharpen method (which simply loads te high res image in the image view) call to both methods so that it will be called if the user scrolls or if the start over button is pressed.
I hope this helps!
检查您的
UIScrollView
的委托是否已设置,或者是否设置为 nil。一般是这样设置的
scrollView.delegate = self
。Check if your
UIScrollView
's delegate is set or not, or was set to nil.Normally set in this way
scrollView.delegate = self
.scrollViewDidEndDecelerating:
并不意味着进行页面布局。您应该实现scrollViewDidScroll:
并根据contentOffset
计算当前可见的页面> 滚动视图。如果可见范围已更改,请添加以前不可见的页面的视图,并删除不再可见的页面。scrollViewDidEndDecelerating:
is not meant to do your page layout in. You should implementscrollViewDidScroll:
and calculate the currently visible page(s) based on thecontentOffset
of the scroll view. If the visible range has changed, add views for the pages that were previously not visible and remove those that are no longer visible.有时只需清理您的项目并重新运行
Shift & 即可。命令& K
移位&命令& Alt & k
Sometimes just clean your project and re-run
Shift & Cmd & K
Shift & Cmd & Alt & k