paginsIsEnabled 时 UIScrollViewDelegate 的 Swift 问题
希望每个人都做得很好。我有一个小问题,我找不到任何解决方案。我有一个滚动视图,我在其中激活了 isPagingEnabled 。滚动视图包含多个尺寸为scrollView.frame.width的图像。我的问题是我正在尝试找到一个解决方案,当滚动视图更改“图片页面”时我会收到通知。我尝试了不同的方法。我尝试过委托scrollViewWillEnd 和DidEnd。我的方法是这样的
var pagePositionOfScrollView = Int(scrollView.contentOffset.x/self.scrollView.frame.width)
var positionActualIncremented = self.positionActual + 1;
print("positionofscroll view page \(positionOfScrollView)")
print("position actual \(positionActualIncremented)")
我发现这个实现有一个问题,用户只能拖动到一半,页面仍然会滚动到下一个,因为 isPagingEnabled,但结束位置仍然在同一页面上所以 pagePositionOfScrollView 将是相同的。 isPagingEnabled 还提供了一种可能性,如果用户以速度滑动,页面会发生更改,但最终的scrollView.contentOffset.x 仍然会位于同一页面上,而不是下一个页面上。 有人有什么想法吗?
hope everyone is doing good. I have a small problem I can't find any solution. I have a scrollView where I activated isPagingEnabled on it. The scrollview contains multiple images the size of the scrollView.frame.width. My problem is I am trying to find a solution where when the scrollView changes the "page of the picture" I am notified. I tried different methods. I have tried with delegate scrollViewWillEnd and both DidEnd. My method was this
var pagePositionOfScrollView = Int(scrollView.contentOffset.x/self.scrollView.frame.width)
var positionActualIncremented = self.positionActual + 1;
print("positionofscroll view page \(positionOfScrollView)")
print("position actual \(positionActualIncremented)")
I have found that with this implementation there is a problem, the user could drag only to half of it, the page will still scroll to the next one because of isPagingEnabled, but the ending position would be still on the same page and so the pagePositionOfScrollView will be the same. As well isPagingEnabled offers the possibility that if the user slides with velocity the page is changed, but the final scrollView.contentOffset.x still gonna be on the same page, not on the next.
Does anybody have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论