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_915106321 小时前
iOS 软件测试工具性能监控、日志分析 KeyMob、Instruments等
android·ios·小程序·https·uni-app·iphone·webview
木叶丸2 小时前
AI 编程概念与 Harness 工程实践入门
人工智能·flutter·ios
zzb15803 小时前
Zed 配置 Swift / iOS 开发
开发语言·ios·swift
全堆鸿蒙12 小时前
25 数据库设计与表结构规划:5 张表的设计思路
数据库·华为·cocoa·harmonyos
colman wang1 天前
Git指令(Mac)
git·macos
黑科技iOS上架1 天前
如何解决AppStore Guideline 5.6被拒
经验分享·ios·ai编程
Geek-Chow1 天前
Mobile App Certificate Pinning: Underlying Principle and a Swift Example
开发语言·ios·swift·安全架构
韩曙亮1 天前
【Flutter】iOS 网络权限设置 ② ( 配置 iOS 平台可使用 HTTP 访问 | ATS 网络安全强制规范 )
网络·flutter·http·ios·https·网络权限·ats
酷虎软件1 天前
分享链接+视频音频文案提取 API 接口文档
ide·macos·xcode
Hyyy2 天前
为什么 macOS 应用一换 Bundle ID,之前授予的权限就全失效了?
macos·electron