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];
}
相关推荐
bybitq13 小时前
Go函数闭包实战-复用函数
ios·golang·xcode
renke336415 小时前
Flutter 2025 跨平台工程体系:从 iOS/Android 到 Web/Desktop,构建真正“一次编写,全端运行”的产品
android·flutter·ios
Zender Han16 小时前
Flutter 中 AbsorbPointer 与 IgnorePointer 的区别与使用场景详解
android·flutter·ios
老臣软件17 小时前
macOS 下载太慢?问题可能不在网速
经验分享·macos·mac·实用软件·网络下载管理器
Clarence Liu18 小时前
MacOS 在Trae IDE中构建现代C++开发环境:从新手到高效的完整指南
c++·ide·macos
Digitally18 小时前
3种简单方法备份 iPhone 短信
ios·iphone
2501_9159214318 小时前
Flutter App 到底该怎么测试?如何在 iOS 上进行测试
android·flutter·ios·小程序·uni-app·cocoa·iphone
二流小码农19 小时前
鸿蒙开发:一个底部的曲线导航
android·ios·harmonyos