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];
}
相关推荐
從南走到北19 小时前
JAVA海外短剧国际版源码支持H5+Android+IOS
android·java·ios
疯笔码良20 小时前
iOS 国际化与本地化完整指南
ios·swift
库奇噜啦呼21 小时前
【iOS】GCD学习
学习·ios·cocoa
Kathleen1001 天前
iOS--TableView的复用机制以及性能优化(处理网络数据)
ios·性能优化·网络请求·gcd·uitableview
tobebetter95271 天前
How to use homebrew on mac
macos·homebrew
信奥胡老师1 天前
苹果电脑(mac系统)安装vscode与配置c++环境,并可以使用万能头文件全流程
c++·ide·vscode·macos·编辑器
子春一1 天前
Flutter 与原生平台深度集成:打通 iOS 与 Android 的最后一公里
android·flutter·ios
依旧风轻1 天前
objc_object 与 objc_class 是一定要了解的底层结构
ios·objective-c·isa·objc_class·objc_object