iOS 键盘弹出视图精准上移

1 视图精准位移,需要计算出输入框距离屏幕底部的距离,然后

计算出输入框需要上移的距离,就是整个视图需要上移的距离,

注意,我们可以自行设置一个适当的buffer,我这里是40,就是输入框距离

键盘有一个40的距离,避免紧挨着 导致体验不佳

复制代码
- (void)keyboardWillShow:(NSNotification *)noti
{
    UpdateUserInfoView  *userInforView = self.editCell.userInfoView;
    
    CGRect userInfoViewframe = [self.editCell convertRect:userInforView.frame toView:window];
    CGFloat bottomSpace = GetScreenHeight()  - CGRectGetMaxY(userInfoViewframe);
    //设置一个buffer
    bottomSpace -= 40;
    CGRect keyboardRect = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat boardHeight = keyboardRect.size.height;
    NSLog(@" keyboardWillShow editCellFrame%@ bottomSpace%f boardHeight%f", NSStringFromCGRect(userInfoViewframe), bottomSpace, boardHeight);

    CGFloat duration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    Weakify(self);
    [UIView animateWithDuration:duration animations:^{
        Strongify(self);
        self.backView.y -= (boardHeight - bottomSpace);
    }];
    [self.tableView addGestureRecognizer:self.endEditingTap];
}
相关推荐
AcceptedLin2 分钟前
删除MacBook启动台内顽固应用程序图标
经验分享·macos
Program Debug5 小时前
Mac安装JDK
java·开发语言·macos
SatVision炼金士6 小时前
Mac 安装Homebrew记录
java·elasticsearch·macos·maven
牛奔7 小时前
Mac 使用 React-Native 使用无线调试商米机,配合Stripe 终端
macos
怎么没有名字注册了啊9 小时前
(Mac)Mac权限问题,运行没有数字签名的dmg
macos
allanGold9 小时前
【Mac】【Vagrant】【类xshell的Termora】centos连接步骤
macos·centos·vagrant
守城小轩10 小时前
Chromium 142 编译指南 macOS篇:安装 Xcode(二)
macos·chrome devtools·浏览器自动化·指纹浏览器·浏览器开发
天庭鸡腿哥1 天前
IOS上收费的软件,Android上免费!
macos·visual studio·everything
天庭鸡腿哥1 天前
大小不足1M,干翻Windows!
microsoft·macos·visual studio·everything
杭城小刘1 天前
Weex 底层原理与 APM
ios·前端框架·weex