CLKeyboardOffsetView 介绍
CLKeyboardOffsetView 是键盘补偿视图工具,为了避免弹出的键盘遮挡输入框,向上移动视图 。
使用方法:
#import "UIView+CLKeyboardOffsetView.h" - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // 打开键盘补偿视图 [self.view openKeyboardOffsetView]; self.view.keyboardGap = 10; // 如果需要自定义键盘与第一响应者之间的间隙,则设置此属性,默认为5 } - (void)viewDiddisappear:(BOOL)animated { [super viewDiddisappear:animated]; // 关闭键盘补偿视图 [self.view closeKeyboardOffsetView]; } 如果需要自定义视图向上移动的高度,则使用代理 <CLKeyboardOffsetViewDelegate> self.view.keyboardOffsetViewDelegate = self; 并添加代理方法 /** * 弹出键盘时,自定义视图向上移动的高度 * * @param firstResponder 第一响应者 * @param keyboardHeight 当前弹出键盘的高度 * @param offsetHeight 默认偏移高度 * * @return 视图向上移动的高度 */ - (CGFloat)offsetViewHeightWithFirstResponder:(UIView *)firstResponder keyboardHeight:(CGFloat)keyboardHeight offsetHeight:(CGFloat)offsetHeight { if ([firstResponder isEqual:_testTextField]) { return keyboardHeight; } return offsetHeight; }
CLKeyboardOffsetView 官网
https://github.com/changelee82/CLKeyboardOffsetView
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。