gpt4 book ai didi

ios - UITextField 和键盘通知 - 奇怪的顺序

转载 作者:IT王子 更新时间:2023-10-29 08:20:33 24 4
gpt4 key购买 nike

所以我已经为键盘出现事件设置了一个通知。现在让我们考虑一个 UITextView 和一个 UITextField。

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];

选择器是:

- (void)keyboardWillShow:(NSNotification *)notification {

keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
}

在 UITextView 的情况下,委托(delegate)方法 - (void)textViewDidBeginEditing:(UITextView *)textViewkeyboardWillShow: 之后 被触发方法。所以 keyboardSize 具有键盘的实际大小,我可以在 textview 委托(delegate)方法中使用它。

但是在 UITextField 的情况下,相应的委托(delegate)方法 - (void)textFieldDidBeginEditing:(UITextField *)textFieldkeyboardWillShow:之前被触发: 方法。

为什么会这样?我如何在文本字段的情况下获取键盘的 CGSize 因为现在它只返回零,因为文本字段委托(delegate)首先被调用而不是键盘选择器。

最佳答案

我遇到过同样的问题。尝试使用:

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView              

关于ios - UITextField 和键盘通知 - 奇怪的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20636352/

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