scrollRangeToVisible 滚动方式与应用内滚动到顶部不同
用户完成编辑后,我尝试滚动到 UITextView 的开头。这工作正常:
[textView scrollRangeToVisible:NSMakeRange(0, 0)];
但是,如果用户滚动到最顶部,我会得到不同的结果;如果用户滚动到顶部,UITextView 有一个很好的填充。如果我以编程方式执行此操作,则不会。我附上了一张屏幕截图来澄清这一点。
我如何以编程方式实现相同的目标,即如果用户滚动到应用程序顶部,不会有什么不同?
我需要对scrollRectToVisible 做一些事情吗? [textView scrollRectToVisible:CGRectMake(0, 0, 0, 0) 动画:是];但没用...但也许我发送了错误的参数。
I am trying to scroll to the beginning of my UITextView after the user is done editing. This works fine:
[textView scrollRangeToVisible:NSMakeRange(0, 0)];
However, I get a different result if the user scrolls to the very top; if the user scrolls to the top, the UITextView has a nice padding. If I do it programatically, it doesn't. I attached a screenshot to clarify this.
How would I achieve the same thing programatically, i.e. that there won't be a difference if the user scrolls to the top of the app?
Would I need to do something with scrollRectToVisible? [textView scrollRectToVisible:CGRectMake(0, 0, 0, 0) animated:YES]; did not work, though... but perhaps I'm sending the wrong parameters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
免责声明:这似乎已停止与 iOS 14 一起使用。
这可能很愚蠢,但您是否尝试过使用负 y 值,例如
?我不知道这是否有效。另外,我不确定它是否适用于零宽度和大小的矩形,所以我宁愿使用
Disclaimer: This seems to have stopped working with iOS 14.
This may be stupid, but have you tried using a negative y value, like
? I have no if this works though. Also, I'm not sure if it works properly for a rect of zero width and size, so I'd rather use
您必须使用以下内容来获取滚动操作中包含的顶部填充:
由于某些奇怪的原因,使用scrollToRect不起作用,即使仍然在iOS14中,也只能指向。
You have to use the following to get the top padding included in the scroll action:
Using scrollToRect doesn't work for some odd reason, even still in iOS14, only to point.