iPhone键盘具有附件视图高度问题 [英] iPhone Keyboard with accessory view height problems

查看:50
本文介绍了iPhone键盘具有附件视图高度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有输入附件视图的键盘,并且我使用了键盘显示显示通知来获取键盘的高度.

I have a keyboard with input accessory view attached, and I used keyboard-Will-Show notification to get height of keyboard.

问题是文本字段第一次成为第一响应者,键盘返回216的高度(没有附件视图的高度).但是第二次关注文本字段时,返回值是216 +附件视图的高度.

The problems is at the first time textfield become first responder, the keyboard return 216 for the height (without accessory view's height). But the second time focus on the textfield, value return is 216 + accessory view's height.

如何获取仅键盘的高度216或216 +附件视图的高度以在其上设置UI框架?

How to get the height of keyboard only 216 or 216 + accessory view's height to setup UI frame base on it ?

推荐答案

我不确定您如何编写代码,但这是我的工作代码:

I am not sure how you do code, but here is my working code for this :

#pragma mark - Keyboard Notification
- (void)keyboardWillShow:(NSNotification *)notification {
    NSDictionary *info = [notification userInfo];
    NSValue *keyBoardEndFrame = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [keyBoardEndFrame CGRectValue].size;
    self.keyboardSize = keyboardSize;
}

- (void)keyboardWillHide:(NSNotification *)notification {
    self.keyboardSize = CGSizeZero;
}


- (void) addToolBarToTextView {

    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
    toolBar.barStyle = UIBarStyleBlack;
    toolBar.translucent = YES;

    UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [doneBtn setFrame:CGRectMake(0, 7, 65, 30)];
    doneBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [doneBtn setTitle:@"Next" forState:UIControlStateNormal];
    [doneBtn addTarget:self action:@selector(keyBoardDoneButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * barItem = [[UIBarButtonItem alloc] initWithCustomView:doneBtn];

    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

    toolBar.items = [NSArray arrayWithObjects: flexibleSpace, barItem, nil];

    mobileTxtField.inputAccessoryView     = toolBar;
}

-(void)viewDidLoad {
    [super viewDidLoad];
    [self addToolBarToTextView];

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


}

这篇关于iPhone键盘具有附件视图高度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆