键盘隐藏时UIScrollView表现不正常

时间:2014-03-04 11:07:59

标签: ios objective-c uitableview keyboard autolayout

我在UIKeyboardWillHideNotification通知方法中使用此代码:

 - (void)keyboardWillHide:(NSNotification*)aNotification
 {

    NSDictionary* info = [aNotification userInfo];
    // get animation info from userInfo
    NSTimeInterval animationDuration;
    CGRect keyboardFrame;
    [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
    [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardFrame];

    // Set view frame
    [UIView animateWithDuration:animationDuration delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        [self.view setFrame:CGRectMake(0, ([self currentOSVersion] >= 7.0f) ? [self viewTopOffsetForSDK7OrAbove] : 0, self.view.frame.size.width, self.view.frame.size.height+keyboardFrame.size.height-TABBAR_HEIGHT)];
        [self.view layoutIfNeeded];
                  } completion:nil];
 }

我在主视图中有UITableView(我正在为聊天构建控制器)。我也在使用autoLayout。现在当键盘隐藏scrollview时先上升一点然后正常下降。但是动画并不顺畅,因为它首先出现了。

我一直在寻找解决方案很长一段时间但却找不到它为什么会上升。

0 个答案:

没有答案