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];
}
相关推荐
Zender Han3 小时前
Flutter Android 启动页 & App 图标替换(不使用任何插件的完整实践)
android·flutter·ios
—Qeyser7 小时前
Flutter CustomScrollView 自定义滚动视图 - 完全指南
android·flutter·ios
软件小滔7 小时前
我使用MAC WiFi Explorer Pro完成了一次家庭网络“大扫除”
网络·macos·智能路由器·mac·应用推荐·wifi explorer
不爱吃糖的程序媛7 小时前
Kuikly-OH 实践(mac版本)
macos
活蹦乱跳酸菜鱼7 小时前
MAC 发出的一个帧(MAC Frame)及其完整的帧格式
网络·macos
—Qeyser8 小时前
Flutter ListView 列表组件完全指南
android·flutter·ios
qq_448011168 小时前
Mac手动删除应用
macos
游戏开发爱好者89 小时前
如何在 Windows 环境下测试 iOS App,实时日志,CPU监控
android·ios·小程序·https·uni-app·iphone·webview
小鹿软件办公9 小时前
Google Chrome 151 版本将停止 macOS 12 Monterey 支持
chrome·macos
cypking9 小时前
一、Mac 下 JDK + Maven 安装配置文档(Bash 终端 / Source 生效)
java·macos·maven