鍵盤的處理高度

//通知:註冊鍵盤將要出現的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboadWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
   ide

 

 


/**
 *  鍵盤的處理
 */動畫

//鍵盤出現時候調用的事件
-(void) keyboadWillShow:(NSNotification *)note{
    
    //獲取字典:
    NSDictionary *infoDic = note.userInfo;
    if (!_texField.isFirstResponder) return;
    //鍵盤的frame:
    CGSize keyboardSize = [[infoDic objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    //textF一下的高度高度
    CGFloat offY = [UIScreen mainScreen].bounds.size.height-64-_bottomS.bottom-10;
    
    NSLog(@"鍵盤的高度:%.02f ---_textField.height%f",keyboardSize.height,_bottomS.bottom-10);
    NSLog(@"textF一下的高度高度:%.02f",offY);
    
    if (offY < keyboardSize.height) {//鍵盤高度大於textFeild;
        //添加動畫效果:第一種:比較簡單;都同樣:
        [UIView animateWithDuration:0.4 animations:^{
            //直接往上移動控制器視圖:
            self.view.transform = CGAffineTransformMakeTranslation(0, -(keyboardSize.height-offY));
        } completion:nil];
        
    }else if (offY > keyboardSize.height){
        
            }
}orm


//鍵盤消失時候調用的事件
-(void)keyboardWillHide:(NSNotification *)note{
    self.view.transform = CGAffineTransformIdentity;
}
-(void)dealloc{
    ////移除觀察者:方法一
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}server

相關文章
相關標籤/搜索