1. 程式人生 > >監聽鍵盤frame變化

監聽鍵盤frame變化

sub observe div 彈出 cga inf style chang cati

/**
 * 監聽鍵盤的彈出和隱藏
 */
- (void)keyboardWillChangeFrame:(NSNotification *)note
{
    // 鍵盤最終的frame
    CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    // 動畫時間
    CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    [UIView animateWithDuration:duration animations:
^{ self.toolBar.transform = CGAffineTransformMakeTranslation(0, keyboardF.origin.y - kScreenHeight); }]; } - (void)setupTextWordToolBar{ SinceToolBar *toolbar = [SinceToolBar toolBar]; toolbar.backgroundColor = [UIColor redColor]; toolbar.width = self.view.width; toolbar.height
= 44; toolbar.y = self.view.height - toolbar.height; [self.view addSubview:toolbar]; self.toolBar = toolbar; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; }

監聽鍵盤frame變化