UITextView 是否使第一行当前光标位置?
长话短说,我需要一个 UITextView 自动滚动到当前光标行,但是我还需要一件事。我需要将光标行专门作为 textView 的第一行显示在视图中,而不是仅仅让 TextView 在“视图中”滚动。
有什么想法如何实现这一点?
谢谢。
Long story short I need to get a UITextView to automatically scroll to the current cursor line, however I need one additional thing. Instead of just having the TextView be scrolled "in view", I need the cursor line to be in view specifically as the first line of the textView.
Any ideas how to accomplish this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[UITextView -selectedRange] 将返回插入点作为位置成员
[UITextView -scrollRangeToVisible:] 将滚动到指定范围
结合两者将使您能够滚动到当前光标行。
根据您的评论,听起来您最有可能希望在显示键盘时调整文本视图的框架。
Apple 提供了一些不错的通知:
UIWindow 类参考 - 通知
UIWindow 类参考 - 用户信息键
确保检查支持的操作系统版本,因为 iOS 5.0 带来了一些新的、更好的、通知和用户信息字典
[UITextView -selectedRange] will return the insertion point as the location member
[UITextView -scrollRangeToVisible:] will scroll to the specified range
Combining the two will enable you to scroll to the current cursor line.
Based on your comment, it sounds like you most likely want to adjust the frame of the text view when the keyboard is shown.
Apple provides some nice notifications:
UIWindow Class Reference - Notifications
UIWindow Class Reference - User Info keys
Make sure to check the supported operating system version as iOS 5.0 brought some new, and better, notifications and user info dictionaries