简体   繁体   English

UITextView位置不正确

[英]UITextView not positioned correctly

Hi I have UITextView that I want it to make its height right above the keyboard. 嗨,我有UITextView,我希望它使其高度在键盘上方。 I am making a notes app and I need to bring the UITextView up so it scroll easily.Here is the code: 我正在做一个笔记应用程序,我需要调出UITextView以便它轻松滚动。以下是代码:

CGRect keyboardBounds = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect frame = self.notesTextView.frame;
CGFloat height = self.notesTextView.frame.size.height;
height = frame.size.height;
frame.size.height -= keyboardBounds.size.height;
self.notesTextView.frame = frame;

However the screen turns out like this: 但是屏幕显示如下: 在此处输入图片说明

Here's the answer you need: https://stackoverflow.com/a/1127025/189804 这是您需要的答案: https : //stackoverflow.com/a/1127025/189804

Doing this right is hard but essential. 做到这一点很困难,但必不可少。 Don't forget to use all the information in the info dictionary passed to the keyboard notification, You need to read the height of the emerging keyboard rather than hard-coding a value, you need to get the animation duration so you can rearrange your views with the same animation duration and you also need to respond to events while editing - imagine that a user begins editing, then decides to connect a bluetooth keyboard to make the editing task easier, or they begin editing with the keyboard connected and then the keyboard battery quits... 不要忘记使用传递给键盘通知的信息字典中的所有信息,您需要读取新兴键盘的高度,而不是对值进行硬编码,您需要获取动画持续时间,以便可以重新排列视图具有相同的动画持续时间,并且您还需要在编辑时响应事件-假设用户开始编辑,然后决定连接蓝牙键盘以简化编辑任务,或者先连接键盘然后再用键盘电池进行编辑退出...

You need to resize the scroll view. 您需要调整滚动视图的大小。 Don't touch the textview's frame ever (unless you make a subclass). 永远不要触摸textview的框架(除非创建子类)。

CGRect frame = self.textView.enclosingScrollView.frame;
frame.size.height = 42;
self.textView.enclosingScrollView.frame = newFrame;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM