IQKeyboardManager Github地址html
常常在開發一個應用程序,咱們遇到了一個問題,iPhone的鍵盤上滑覆蓋的UITextField / UITextView
。IQKeyboardManager
能夠防止鍵盤滑動問題和覆蓋UITextField / UITextView
無需你輸入任何代碼,不須要額外的設置要求。使用IQKeyboardManager你只須要添加源文件到你的項目。app
主要特色框架
1)無代碼
2)自動工做
3)沒有更多的UIScrollView
4)沒有更多的子類
5)沒有更多的手動工做
6)沒有更多#imports
less
截圖ide
IQKeyboardManager 支持 CocoaPods工具
pod ‘IQKeyboardManager’this
管理es5
若是你不使用storyboard
或xib
創造你的視圖。你須要重寫-(void)UIViewController loadview
方法,須要設置一個UIScrollView
實例self.view
。spa
-(void)loadView{ UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.view = scrollView;}
IQKeyboardManager
若是你想在某個 viewcontroller
禁用 IQKeyboardManager
你應該在 ViewDidAppear
中禁用IQKeyboardManager
,而在ViewWillDisappear
啓用它
代碼:code
#import "IQKeyboardManager.h"@implementationExampleViewController { BOOL _wasKeyboardManagerEnabled;} -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; _wasKeyboardManagerEnabled = [[IQKeyboardManager sharedManager] isEnabled]; [[IQKeyboardManager sharedManager] setEnable:NO]; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[IQKeyboardManager sharedManager] setEnable:_wasKeyboardManagerEnabled];} @end
IQKeyboardReturnKeyHandler
在 ViewController
的 viewDidLoad
中代碼:
@implementationViewController {IQKeyboardReturnKeyHandler *returnKeyHandler; } - (void)viewDidLoad { [super viewDidLoad]; returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self]; }
改變鍵盤上的返回鍵。
-(void)dealloc { returnKeyHandler = nil; }
textField.inputAccessoryView = [[UIView alloc] init];
代碼:
-(void)viewDidLoad { [super viewDidLoad]; //Adding done button for textField1 [textField1 addDoneOnKeyboardWithTarget:self action:@selector(doneAction:)]; //Adding previous/next/done button for textField2 [textField2 addPreviousNextDoneOnKeyboardWithTarget:self previousAction:@selector(previousAction:) nextAction:@selector(nextAction:) doneAction:@selector(doneAction:)]; //Adding cancel/done button for textField3 [textField3 addCancelDoneOnKeyboardWithTarget:self cancelAction:@selector(cancelAction:) doneAction:@selector(doneAction:)];} /*! previousAction. */ -(void)previousAction:(id)button{ //previousAction } /*! nextAction. */ -(void)nextAction:(id)button{ //nextAction } /*! doneAction. */ -(void)doneAction:(UIBarButtonItem*)barButton{ //doneAction } /*! cancelAction. */ -(void)cancelAction:(UIBarButtonItem*)barButton{ //cancelAction }
UIKeyboard 處理
+(instancetype)sharedManager : Returns the default singleton instance. @property BOOL enable : Use this to enable/disable managing distance between keyboard & textField/textView). @property CGFloat keyboardDistanceFromTextField : Set Distance between keyboard & textField. Can't be less than zero. Defaultis10.@property BOOL preventShowingBottomBlankSpace : Prevent to show bottom blanck area when keyboard slide up the view.
IQToolbar
處理@property BOOL enableAutoToolbar : Enable autoToolbar behaviour. If It is set to NO. You have to manually create UIToolbar for keyboard. Defaultis YES. @property IQAutoToolbarManageBehaviour toolbarManageBehaviour : Setting toolbar behaviour to IQAutoToolbarBySubviews to manage previous/next according to UITextField's hierarchy in it's SuperView. Set it to IQAutoToolbarByTag to manage previous/next according to UITextField's tag propertyin increasing order. Defaultis IQAutoToolbarBySubviews. @property BOOL shouldToolbarUsesTextFieldTintColor : If YES, then uses textField's tintColor propertyfor IQToolbar, otherwise tintColor is black. Defaultis NO. @property BOOL shouldShowTextFieldPlaceholder : If YES, then it add the textField's placeholder text on IQToolbar. Defaultis YES. @property UIFont *placeholderFont : placeholder Font. Defaultis nil. Defaultis YES.
UITextView
處理@property BOOL canAdjustTextView : Giving permission to modify TextView's frame. Adjust textView's frame when it is too big in height. Defaultis NO. @property BOOL shouldFixTextViewClip : Adjust textView's contentInset to fix fix for iOS 7.0.x -(#Stackoverflow). Defaultis YES.
@property BOOL overrideKeyboardAppearance : Override the keyboardAppearance for all textField/textView. Defaultis NO. @property UIKeyboardAppearance keyboardAppearance : If overrideKeyboardAppearance is YES, then all the textField keyboardAppearance issetusing this property.
UITextField/UITextView
@propertyBOOL shouldResignOnTouchOutside : Resign textField if touched outside of UITextField/UITextView. -(void)resignFirstResponder : Resigns currently first responder field.
UISound
處理@property BOOL shouldPlayInputClicks : If YES, then it plays inputClick sound onnext/previous/done click. Defaultis NO.
UIAnimation
@property BOOL shouldAdoptDefaultKeyboardAnimation : If YES, thenuses keyboard default animation curve style to move view, otherwise uses UIViewAnimationOptionCurveEaseOut animation style. Defaultis YES.
1)支持設備方向。
2)啓用/禁用鍵盤消息時,須要設置 enable
的布爾值。
3)簡單的集成。
4)做爲一個textField/textView
的AutoHandle UIToolbar
須要設置 enableAutoToolbar
的布爾值。
5)能夠由父視圖AutoHandle UIToolbar
或textField/textView
,使用toolbarManageBehaviour
枚舉。
6)方便地添加上下和完成按鈕鍵盤UIToolbar UIView
類,自動使用enableAutoToolbar
布爾值。
7)啓用/禁用,下/上一個按鈕類的方法,自動使用enableAutoToolbar
布爾值。
8)鍵盤設置距離文本框使用keyboardDistanceFromTextField
。
9)鍵盤觸摸外面用shouldResignOnTouchOutside.
禁用。
10)管理的框架時,UITextView
高度太大,使用canAdjustTextView
設置適合屏幕。
11)適用在UITableView/UIScrollView
中的UITextField/UITextView
12)能夠輸入聲音在點擊「下/上一頁/完成」時。
延伸閱讀:
IQKeyboardManager
iOS自動處理鍵盤事件的第三方庫:IQKeyboardManager
以上就介紹了iOS 鍵盤自適應(IQKeyboardManager)使用小結,包括了方面的內容,但願對IOS開發有興趣的朋友有所幫助。
本文網址連接:http://www.codes51.com/article/detail_117701.html