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];
}
相关推荐
Daniel_Coder1 分钟前
Xcode 中常用图片格式详解
ios·xcode·swift
瓜子三百克37 分钟前
Objective-C 路由表原理详解
开发语言·ios·objective-c
fengyun28912 小时前
Mac电脑 卸载工具 App Cleaner
macos
RyanGo3 小时前
iOS断点下载
ios·swift
蒙小萌19934 小时前
找工作-iOS开发-3年经验-AI协作开发
ios
aerror5 小时前
Xbox One 控制器转换为 macOS HID 设备的工作原理分析
macos·xbox
丶皮蛋菌6 小时前
关于OC与Swift内存管理的解惑
ios
杂雾无尘7 小时前
掌握生死时速:苹果应用加急审核全攻略!
ios·swift·apple
晴风向上7 小时前
mac mini m4安装node.js@16以下版本方法
macos·node.js
HarderCoder7 小时前
Swift 6.2 中的 `@concurrent`
ios·swift