UIScollView 中的 UITextField 导致滚动问题
我在 UIScrollView 中有一个高度定制的 UITextField。当用户在文本字段中输入字符时,我正在计算我想要滚动视图的 contentOffset 的位置并进行设置。输入第一个字符后,滚动视图就可以正常工作了。
输入下一个字符后,我再次将偏移量设置为同一点,但由于某种原因,当重绘发生时,它将偏移量重置回 0,0。第三次设置偏移量有效,然后在输入第四个字符后,它会重置回 0,0。最终的影响是,输入每个字符后,滚动视图在我想要的偏移量和 0,0 之间来回反弹。
我已经验证我每次都将偏移量设置为同一点,并且我没有在代码中的其他任何地方重置偏移量。
这个问题一直让我发疯,所以任何关于这可能是什么或如何调试它的方向都将非常感激。
I have a heavily customized UITextField in a UIScrollView. When the user enters a character into the textfield I am calculating where I want the contentOffset of the scrollview and I'm setting it. That works fine after the first character is entered, the scroll view goes where its supposed to.
After the next character is entered I set the offset again to the same point but for some reason, when the redraw occurs, it resets the offset back to 0,0. Setting the offset a third time works and then after a forth character is entered it resets back to 0,0. The net affect is that the scrollview bounces back and forth between the offset I want and 0,0 after each character is entered.
I've verified that I'm setting the offset to the same point each time and that I'm not resetting the offset anywhere else in my code.
This issue has been driving me crazy so any direction regarding what this could be or how to debug it would really be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中所述,如果没有任何代码,我们能做的事情就会受到限制。但是,我认为您的问题可能有一个相当简单的解决方案。在设置内容偏移之前,请检查当前的内容偏移,如果它已经正确,则不必费心重置它。
As stated in the comments, without any code there is a limit to what we can do. However, I think there might be a rather simple solution to your problem. Before setting the content offset check the current content offset and if it's already correct don't bother resetting it.