[英]Keyboard not hidden in ios
我在屏幕底部固定了一个UITextView(用途:注释),当用户要添加注释时,键盘将出现,并且注释视图与注释一起向上移动。 我也有一个取消按钮来隐藏键盘,但是键盘没有隐藏
//Set up NSNotification for Keyboard
-(void) viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillToggle:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillToggle:)
name:UIKeyboardWillHideNotification object:nil];
}
//Code to shift comment view up with keyboard
- (void) keyboardWillToggle:(NSNotification *)aNotification
{
CGRect frame = [self.navigationController.toolbar frame];
CGRect keyboard = [[aNotification.userInfo valueForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
frame.origin.y = keyboard.origin.y - frame.size.height;
[UIView animateWithDuration:[[aNotification.userInfo valueForKey:@"UIKeyboardAnimationDurationUserInfoKey"] floatValue] animations:^
{
[self.navigationController.toolbar setFrame:frame];
}];
}
//Hide keyboard
-(void)cancelComment:(UIBarButtonItem*)sender{
NSLog(@"cancelComment called");
[self.view endEditing:YES];
}
我觉得这应该工作吗? “ cancelComment named”正在被记录到控制台,但是键盘没有被隐藏
解:
您忘了放:
[yourtextfield resignfirstresponder];
在您的cancelComment函数中。
你可以试试
-(void)cancelComment:(UIBarButtonItem*)sender{
NSLog(@"cancelComment called”);
[self.navigationController.view endEditing:YES];
}
我认为您不在self.view和self.navigationController.view中的textView
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[yourtextfieldname resignfirstresponder];
}
希望你能!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.