简体   繁体   English

我如何知道用户何时到达NSTextView中的文本结尾

[英]How do I know when a user has reached the end of the text in NSTextView

My users are reading readonly text in a UITextView . 我的用户正在UITextView中读取只读文本。 When they have finished reading a selection, I would like to be able to display a Completed Reading button. 当他们阅读完所选内容后,我希望能够显示“ Completed Reading按钮。 How can I detect when the user has scrolled to the end of the text? 如何检测用户何时滚动到文本的结尾?

Try this. 尝试这个。 First before each read calculate the size of the text in the textview based upon the size of its widt. 首先,在每次读取之前,根据文本宽度的大小计算textview中文本的大小。 Then from there check if the content offset of the textview has reached the size of the maxSize of the text that was loaded in the text view. 然后从那里检查textview的内容偏移量是否已达到在文本视图中加载的文本的maxSize的大小。

Try this: 尝试这个:

float scrollerPosition = [[[textView superview] verticalScroller] floatValue];

The scroller position should be between 0.0 and 1.0 . 滚动条的位置应在0.01.0之间。

I don't think it's right to consult the vertical scroller's position. 我认为查询垂直滚动条的位置不正确。 What happens if the scroll view is large to enough to show the whole text view without scrolling? 如果滚动视图大到足以显示整个文本视图而不滚动,会发生什么? Is the scroller at 0.0 or 1.0? 滚动条是0.0还是1.0?

I think you should consult the scroll view's -documentVisibleRect and compare it to the text view's -bounds . 我认为您应该查阅滚动视图的-documentVisibleRect并将其与文本视图的-bounds进行比较。 If the NSMaxY() of the former is greater than or equal to the NSMaxY() of the latter, then the text view's bottom is visible. 如果前者的NSMaxY()大于或等于后者的NSMaxY() ,则文本视图的底部可见。 If the text view might also scroll horizontally and you care if they scrolled all the way to the right, also check the NSMaxX() of both rects in the same way. 如果文本视图也可能水平滚动,并且您关心它们是否一直向右滚动,则还要以相同的方式检查两个NSMaxX()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何知道UITextField的文本是否已被用户修改 - How do I know if the text of a UITextField has been modified by user 我如何知道页面未能加载到UIWebView中而不是被用户“停止”? - How do I know when a page has failed to load in UIWebView as opposed to being “Stopped” by the user? iPhone如何知道用户何时触摸屏幕但不移动? - iPhone how do I know when the user is touching the screen but not moving? 如何在 SwiftUI 中查找滚动视图内容是否已到达内容末尾 - How to find if scrollview content has reached its end of the content in SwiftUI 我怎么知道CATiledLayer何时渲染了所有可见的图块? - How do I know when a CATiledLayer has rendered all visible tiles? 我怎么知道NSXmlParser何时终止对StopActivating的UIActivityIndi​​catorView的解析? - how can i know when the NSXmlParser End Parsing for StopAnimating The UIActivityIndicatorView? 我如何知道用户何时从Alphabet更改为Numeric iOS - How do I know when user change from Alphabet to Numeric iOS 我如何知道文本是否超出了文本视图的范围? - How do I know if text exceeds the bounds of a text view? 如何判断SKEmitterNode何时达到最大粒子数? - How can I tell when a SKEmitterNode has reached its maximum particles? 我如何知道编译器是否已启用ARC支持? - How do I know whether the compiler has ARC support enabled?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM