gpt4 book ai didi

ios - 键盘未隐藏在 ios 中

转载 作者:行者123 更新时间:2023-11-28 19:37:41 25 4
gpt4 key购买 nike

我在屏幕底部固定了一个 UITextView(用途:评论),当用户想要添加评论时,键盘出现,我让评论 View 随着评论一起向上移动。我还有一个隐藏键盘的取消按钮,但键盘没有隐藏

//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 called”正在记录到控制台,但键盘未隐藏

最佳答案

解决方案:

你忘了放:

[yourtextfield resignfirstresponder];

在您的 cancelComment 函数中。

关于ios - 键盘未隐藏在 ios 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37226887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com