@property (nonatomic,assign)float currentf_heihgt; //當前tf的高度
@property (nonatomic,assign)float currentf_y;? //當前tf的y值袜啃,方便獲得keyborard移動
#define FUll_VIEW_WIDTH ([[UIScreen mainScreen] bounds].size.width)
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
? ? UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
? ? CGRect rect=[textField convertRect: textField.bounds toView:window];
? ? _currentf_y = rect.origin.y;
? ? _currentf_heihgt = textField.frame.size.height;
? return YES;
}
-(void)keyboardWillShow:(NSNotification*)aNotification {
? ? //獲取鍵盤的高度
? ? NSDictionary *userInfo = [aNotification userInfo];
? ? NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
? ? CGRect keyboardRect = [aValue CGRectValue];
? CGFloat keyboardheight = keyboardRect.size.height;
? ? //計算出鍵盤頂端到inputTextView panel底端的距離(加上自定義的緩沖距離INTERVAL_KEYBOARD)
? ? //如果大于0,則鍵盤將輸入框遮擋蛉顽,需調(diào)節(jié)高度熊户,小于0畸肆,則不需要調(diào)節(jié)
? ? CGFloat offset = _currentf_y + _currentf_heihgt - (FUll_VIEW_HEIGHT - keyboardheight);
? ? //取得鍵盤的動畫時間泡徙,這樣可以在視圖上移的時候更連貫
? ? double duration = [[aNotification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
? ? //將視圖上移計算好的偏移
? ? NSLog(@"........%f",offset);
? ? if(offset > 0) {
? ? ? ? [UIView animateWithDuration:duration animations:^{
? ? ? ? ? ? blackGroundView.frame = CGRectMake(0.0f,-offset, blackGroundView.frame.size.width, blackGroundView.frame.size.height);
? ? ? ? }];
? ? ? ? NSLog(@"hhhahjfjhsffksfkjs");
? ? }
}
-(void)keyboardwillHiden:(NSNotification*)notification{
? double duration=? [[[notification userInfo]objectForKey:UIKeyboardAnimationDurationUserInfoKey]doubleValue];
? ? [UIView animateWithDuration:duration animations:^{
? ? ? ? blackGroundView.frame = CGRectMake(0.0f,NAVIGATION_BAR_HEIGHT, blackGroundView.frame.size.width, blackGroundView.frame.size.height);
? ? }];
}