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];
}
相关推荐
2501_9160074710 小时前
跨平台 App 安全,Flutter、RN、Unity、H5 混合应用加固
android·ios·小程序·https·uni-app·iphone·webview
新 一.11 小时前
uniapp在ios上真机测试运行
ios·uni-app
2501_9160074712 小时前
不越狱如何查看iOS 应用的详细信息及其文件目录结构
android·macos·ios·小程序·uni-app·cocoa·iphone
handsome091612 小时前
上传app store和IOS更新版本的实战流程
ios·打包上架
芒鸽14 小时前
macos上Rust 命令行工具鸿蒙化适配完全攻略
macos·rust·harmonyos
山有木兮啊14 小时前
VSCode Remote-SSH 连接Mac卡在初始化VSCode
vscode·macos·ssh
2501_9160088915 小时前
无需钥匙串快速创建 iOS 开发 / 发布证书 P12 CSR
android·ios·小程序·https·uni-app·iphone·webview
一个写bug的程序员16 小时前
Mac自启服务关闭方式
macos
梁下轻语的秋缘16 小时前
初学者避坑指南:Mac 虚拟机搭建 Keil5 STM32 环境 + 解决 ST-Link USB Command Error 报错
windows·stm32·macos
天荒地老笑话么16 小时前
macOS 终端:本机隐藏用户名,但 SSH 登录时仍显示(Oh My Zsh + agnoster,更安全)
windows·macos·网络安全