鍵盤之上的工具欄,完美實(shí)現(xiàn),動(dòng)畫無缺陷

//鍵盤代理事件
- (void)keyboardWillHide:(NSNotification *)notification{
    _keyBoardShowIng = NO;
    [UIView animateWithDuration:.25 animations:^{
        downView.top = MainScreenHeight;
        if (_richTextToolBar) {
            dispatch_async(dispatch_get_main_queue(), ^{
                 _richTextToolBar.hidden = YES;
            });
           
        }
    }];
    
}

- (void)keyboardWillShow:(NSNotification *)notification{
    _keyBoardShowIng = YES;
     NSDictionary *userInfo = [notification userInfo];
     NSValue * endValue   = [notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
     CGFloat height = [endValue CGRectValue].size.height;
     if(height==0) return;

    
    NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    
    NSNumber *curve = [userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
    
    // 添加移動(dòng)動(dòng)畫,使視圖跟隨鍵盤移動(dòng)
    
    [UIView animateWithDuration:duration.doubleValue animations:^{
        
        [UIView setAnimationBeginsFromCurrentState:YES];
        
        [UIView setAnimationCurve:[curve intValue]];
        
        downView.bottom = MainScreenHeight - height;
        
    }];
}

但是記得下面

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];

}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容