当键盘可见时,我需要减小文本视图大小,我不想与键盘重叠。知道如何获得键盘参考,以编程方式创建NSLayoutConstraint
?
答案 0 :(得分:0)
我认为这是可能的,根据我的视图尝试这不是设置Constrain但你可以调整TextView的大小。
ViewDidLoad方法中的写入通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardWillHideNotification object:nil];
当KeyBoard显示为
时设置textview大小- (void) keyboardDidShow:(NSNotification *)aNotification
{
self.textView.frame=CGRectMake(As Your needed size);
}
如果你想在KeyBoard解雇时制作然后我想要我的TextView尺寸,那么你设置新的方法,如
- (void) keyboardDidHide:(NSNotification *)aNotification
{
self.textview.frame=cgrectmake(As your Exact Size);
}
并为textview编写Resign First Responder方法,如果你想要它像
那样-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.textView resignFirstResponder];
}