2014-09-29 21 views
6

Tôi có một bàn phím với chế độ xem phụ kiện đầu vào được đính kèm và tôi đã sử dụng thông báo bàn phím-Sẽ hiển thị để có chiều cao bàn phím.Bàn phím iPhone có các vấn đề về độ cao xem phụ kiện

Các sự cố ở trường văn bản đầu tiên trở thành trả lời đầu tiên, bàn phím trả về 216 cho chiều cao (không có chiều cao của phụ kiện). Nhưng lần thứ hai tập trung vào trường văn bản, giá trị trả lại là 216 + chiều cao của phụ kiện xem.

Cách lấy chiều cao của bàn phím chỉ 216 hoặc 216 + chiều cao của chế độ xem phụ kiện để thiết lập khung giao diện người dùng dựa trên nó?

Trả lời

2

Tôi không chắc chắn làm thế nào bạn làm mã, nhưng đây là mã làm việc của tôi cho điều này:

#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]; 


} 
+1

Cảm ơn, nó làm việc như một nét duyên dáng! – longtranz

Các vấn đề liên quan