使用SetContentOffset或scrollRectToVisible后UIScrollView冻结

发布于 2024-10-27 22:09:13 字数 470 浏览 1 评论 0 原文

我有一个启用了分页的 UIScrollView,我希望能够跳到下一行的页面,而不是滑动浏览每个页面。我尝试同时使用setContentOffset和scrollRectToVisible。它们都将视图滚动到正确的点,但在滚动动画或不动画后,滚动视图会冻结并且对任何触摸都没有响应。我尝试将其设置为第一响应者,但没有任何改变。我在滚动视图之外有一个按钮,在 setContentOffset 之后它仍然可以正常工作。滚动视图内部也有按钮,滚动视图不仅不会响应拖动的触摸,而且按钮也不会识别触摸。

        [mainScroll setContentOffset:CGPointMake(mainScroll.frame.size.width*4, 0.0) animated:YES];

太棒了;我可以很好地滚动视图,浏览所有页面,但是当我尝试调用 setContentOffset 或scrollRectToVisible 时,我会在移动后“冻结”。

I have a UIScrollView with paging enabled and I want to be able to jump to pages further down the line rather then swiping through each one. I attempted to use both setContentOffset and scrollRectToVisible. They both scroll the view to the correct point but after scrolling animated or not the scrollview becomes frozen and unresponsive to any touches. I tried setting it to the first responder but it changed nothing. I have a button outside of the scroll view and it still functions fine after the setContentOffset. There are also buttons inside the scrollview and not only will the scrollview not respond to touch for dragging but the buttons will not recognize the touches either.

        [mainScroll setContentOffset:CGPointMake(mainScroll.frame.size.width*4, 0.0) animated:YES];

tldr; I can scroll through the view fine, through all the pages but when I try and call a setContentOffset or a scrollRectToVisible I get 'frozen' after the move.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2024-11-03 22:09:13

我明白了,愚蠢的错误。

在我的scrollViewDidScroll中,我有:

scrollView.userInteractionEnabled=NO;

在我的scrollViewDidEndDecelerating

scrollView.userInteractionEnabled=YES;

和scrollViewDidEndDragging:willDecelerate中,

if(!decelerate){scrollView.userInteractionEnabled=YES;}

我有这个来防止按钮按下和页面转换期间的任何随机事件。但是,当调用 setContentOffset 时,它只会导致scrollViewDidScroll 被调用,而其他两个都不会被调用,因此 UserInteraction 从未被设置回 Enabled,而仅在使用 setContentOffset 时才被设置回 Enabled。

简单修复。

I figured it out, stupid mistake.

In my scrollViewDidScroll I had:

scrollView.userInteractionEnabled=NO;

and in my scrollViewDidEndDecelerating

scrollView.userInteractionEnabled=YES;

and in scrollViewDidEndDragging:willDecelerate

if(!decelerate){scrollView.userInteractionEnabled=YES;}

I had this to prevent button presses and any random things during a page transition. But when setContentOffset is called it only causes scrollViewDidScroll to be called and neither of the other two, so the UserInteraction was never set back to Enabled, but only when using setContentOffset.

Simple fix.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文