CLKeyboardOffsetViewiOS 鍵盤視圖
使用方法:
#import "UIView+CLKeyboardOffsetView.h"
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// 打開鍵盤補償視圖
[self.view openKeyboardOffsetView];
self.view.keyboardGap = 10; // 如果需要自定義鍵盤與第一響應(yīng)者之間的間隙,則設(shè)置此屬性,默認為5
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
// 關(guān)閉鍵盤補償視圖
[self.view closeKeyboardOffsetView];
}
如果需要自定義視圖向上移動的高度,則使用代理
<CLKeyboardOffsetViewDelegate>
self.view.keyboardOffsetViewDelegate = self;
并添加代理方法
/**
* 彈出鍵盤時,自定義視圖向上移動的高度
*
* @param firstResponder 第一響應(yīng)者
* @param keyboardHeight 當前彈出鍵盤的高度
* @param offsetHeight 默認偏移高度
*
* @return 視圖向上移動的高度
*/
- (CGFloat)offsetViewHeightWithFirstResponder:(UIView *)firstResponder
keyboardHeight:(CGFloat)keyboardHeight
offsetHeight:(CGFloat)offsetHeight
{
if ([firstResponder isEqual:_testTextField])
{
return keyboardHeight;
}
return offsetHeight;
}評論
圖片
表情
