iOS 鍵盤視圖 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; }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!