重置 UITextView 中的选择光标

发布于 2024-11-18 20:47:33 字数 584 浏览 0 评论 0原文

我看过类似标题的问题,例如:

UITextView 禁用文本选择

但这不是'这不正是我想要实现的目标。

我的应用程序有一个仅需要垂直滚动的 UITextView。当按住触摸时,光标明显出现在触摸点处。但是,当我更改视图的文本时,光标始终放在 UITextView 的末尾,这当然会将我的文本一直滚动到底部。我尝试设置选定的范围,但即使将可编辑设置为“否”,这也会导致键盘弹出。我希望我的视图能够显示文本并垂直滚动,并且能够在更改文本时重置其滚动位置。如果我能实现这一点并且无法选择、复制、粘贴、编辑等,我会非常满意。

上次我尝试处理这个问题时我放弃了并最终使用了 UILabel,但是这次我需要能够滚动。我最好将 UILabel 放在滚动视图中作为解决方法吗?或者也许释放textView会起作用,但由于我将它作为IB中的引用出口挂钩,我想我必须以编程方式重新创建它,并且如果可以的话,我想避免如此棘手的事情。

我已经无能为力了,我一直觉得应该很简单,所以提前感谢您的任何和所有帮助!

I've looked at similarly titled questions, such as :

UITextView disabling text selection

but that wasn't quite what I was trying to achieve.

My app has a UITextView that only requires vertical scrolling. When holding down a touch, the cursor obviously appears at the point of the touch. However, when I change the text of the view, the cursor is always put at the end of the UITextView, which of course scrolls my text all the way to the bottom. I've tried setting the selected range, but even with the editable set to NO, this causes the keyboard to popup. I want my view to be able to display my text and vertically scroll, and to be able to reset its scroll position when I change the text. If I could achieve this and not be able to select, copy, paste, edit, etc. I would be perfectly content.

The last time I tried to deal with this I gave up and ended up using a UILabel, however I need to be able to scroll this time around. Would I be better off putting a UILabel inside a scroll view as a work around? Or perhaps releasing the textView would work, but since I have it hooked as a referencing outlet in IB, I imagine I would have to recreate it programmatically, and I'd like to avoid something so hacky if I can.

I'm at my whit's end with something I've always felt should be simple, so thanks in advance for any and all help!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文