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];
}
相关推荐
黑科技iOS上架7 小时前
双引擎解决oc/swift开发引用加固难题
开发语言·ios·swift·审核·ios混淆·执行程序差异化
wechatbot8888 小时前
企微第三方自动化开发:原生能力无阉割 API 开放平台介绍
后端·ios·微信·企业微信·ai编程·ipad
黑科技iOS上架8 小时前
iOS framework/dylib动态库定向加固实战
macos·ios·objective-c·cocoa·审核·ios混淆·执行程序差异化
可乐鸡翅yeah_1 天前
fmp4 碎片 MP4 格式 HLS 流,和传统 TS 分片有什么不一样
开发语言·javascript·ios·音视频·safari·m3u8·m3u8在线播放
神奇的小猴程序员1 天前
苹果Mac电脑玩我的世界没有版本?用PCL-R即可!
macos
茶底世界之下1 天前
为什么高精度透明图片上传到 Metal 时,必须把“拷贝像素”与“混合合成”分开
ios
灵韵aura1 天前
macOS 的指令缩写
macos
老李IT笔记1 天前
iOS 27 更新延迟只能给 1 到 90 天:两个参数怎么配,配错了会发生什么
ios·智能手机
Helix2501 天前
移动端浏览器内核之争:iOS 为何强制使用 WebKit?
ios·safari·webkit·wkwebview·浏览器内核·blink·ios浏览器内核