无需 UIKeyboardWillShowNotification 即可获取键盘大小
我想在不使用可用键盘通知的情况下获取键盘的大小。原因是我在视图上有几个文本字段,并且我不需要调整所有文本字段的视图大小,正如我在几乎每个示例中看到的那样。我只需要调整编辑时位于键盘后面的某些文本字段/视图的视图大小。所以我使用 textFieldDidBeginEditing
和 textFieldDidEndEditing
方法,因为在这里我知道正在编辑什么文本字段。另一个问题是,即使我订阅键盘通知,UIKeyboardWillShowNotification
也会在 textFieldDidBeginEditing
之后触发,因此我无法在第一次激活时获取键盘大小。我假设键盘通知功能未提供任何信息,其中实际文本字段或视图可用。
The following code works but I need the keyboard size:
- (void) textFieldDidBeginEditing:(UITextField *) textField {
if ([theControls containsObject: textField]) {
[UIView beginAnimations: @"szar" context: nil];
[UIView setAnimationDuration:0.3];
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, -216);
[UIView commitAnimations];
}
}
- (void) textFieldDidEndEditing:(UITextField *) textField {
if ([theControls containsObject: textField]) {
[UIView beginAnimations: @"szar" context: nil];
[UIView setAnimationDuration:0.3];
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, +216);
[UIView commitAnimations];
}
}
I want to get the size of the keyboard without using the keyboard notifications available. The reason is I have several text field on the view and I don't need to resize the view for all of them, as I have seen in nearly every example. I just need to resize the view for some of the text fields/views that will be behind the keyboard when editing. So I'm using textFieldDidBeginEditing
andtextFieldDidEndEditing
methods, because here I know what textfield is being edited. Another problem is that even if I subscribe to the keyboard notifications the UIKeyboardWillShowNotification
is fired after textFieldDidBeginEditing
so I cannot get the keyboard size on the first activation. I assume no information is provided from the keyboard notification functions where the actual text field or view is abailable.
The following code works but I need the keyboard size:
- (void) textFieldDidBeginEditing:(UITextField *) textField {
if ([theControls containsObject: textField]) {
[UIView beginAnimations: @"szar" context: nil];
[UIView setAnimationDuration:0.3];
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, -216);
[UIView commitAnimations];
}
}
- (void) textFieldDidEndEditing:(UITextField *) textField {
if ([theControls containsObject: textField]) {
[UIView beginAnimations: @"szar" context: nil];
[UIView setAnimationDuration:0.3];
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, +216);
[UIView commitAnimations];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我仍然使用通知,但没有使用您指定的通知。也许这会更好?只是想提供帮助,我了解这些事情是多么令人沮丧。
编辑:这也可能有助于区分活动文本字段和非活动文本字段
I still used Notifications but not the ones you specified against. Maybe this will work better? Just trying to help, I understand how frustrating these things can be.
Edit: This May Help As Well To Distinguish Active Text Fields From The Non-Active