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];
}
相关推荐
软泡芙5 小时前
【IOS】Codable
ios·ssh·cocoa
nvvas6 小时前
9月苹果发布会前瞻:新iPhone、Apple Watch重点速览
ios·iphone
Zender Han7 小时前
Flutter 自适应(Adaptive)与响应式(Responsive)设计实践:官方推荐方案详解
android·flutter·ios
冯汉栩8 小时前
Swift Control DateSelection(日期选择框)
ios·cocoa·swift
开心就好202510 小时前
appuploader-cli 使用教程:在 Windows 上用命令行把 IPA 上传到 App Store
后端·ios
守城小轩11 小时前
Chromium 148 编译指南 macOS篇:环境配置要求(一)
macos
软泡芙11 小时前
【IOS】CoreBluetooth
ios
冯汉栩11 小时前
Swift Control DashLineView(虚线)
开发语言·ios·swift
Codeking__12 小时前
iOS 动画:core Animation 底层原理
macos·objective-c·cocoa
SatanII12 小时前
读懂 SELinux:强制访问控制 MAC,解决 httpd 服务权限报错实战
linux·运维·服务器·网络·macos