IQKeyboardManager
Slide on the iPhone’s keyboard covered UITextField / UITextView
. IQKeyboardManager
Can prevent keyboard sliding problems and coverage UITextField / UITextView
without you having to enter any code, no additional setting requirements. To use IQKeyboardManager you only need to add source files to your project.
Screenshot
IQKeyboardManager supports CocoaPods
under 'IQKeyboardManager'
management
UINavigationBar
If you don't use storyboard
or xib
create your view. You need to override the -(void)UIViewController loadview
method, you need to set up an UIScrollView
instance self.view
.
-(void)loadView
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = scrollView;
}
Disable for a certain ViewControllerIQKeyboardManager
If you want a viewcontroller
disabled IQKeyboardManager
you should ViewDidAppear
disable in IQKeyboardManager
, and in ViewWillDisappear
turn it
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
The keyboard's enter key processing
1) Create an instance variable is instantiated IQKeyboardReturnKeyHandler
in ViewController
the viewDidLoad
middle
Code:
@implementationViewController
{
IQKeyboardReturnKeyHandler *returnKeyHandler; } - (void)viewDidLoad { [super viewDidLoad]; returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self]; }
Change the return key on the keyboard.
Dealloc method that sets instance variables to zero
-(void)dealloc {
returnKeyHandler = nil;
}
UIToolbar(IQToolbar)
1) If you don’t want to add a specific auto toolbar above the keyboard, you should add a class as its toolbar
textField.inputAccessoryView = [[UIView alloc] init];
2) If you need to control the up/down/finish buttons yourself, you should use the methods of the UIView class to create your text box toolbar.
Code:
-(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
}
Function and use
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
deal with
@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
deal with
@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.
UIKeyboard appearance coverage
@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.
shut downUITextField/UITextView
@propertyBOOL shouldResignOnTouchOutside : Resign textField if touched outside of UITextField/UITextView.
-(void)resignFirstResponder : Resigns currently first responder field.
UISound
deal with
@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.
feature
1) Support device orientation.
2) Enable / disable the keyboard when the message, you need to set enable
a Boolean value.
3) Simple integration.
4) As one textField/textView
of the AutoHandle UIToolbar
need to set the enableAutoToolbar
Boolean value.
5) by the parent may be a view AutoHandle UIToolbar
or textField/textView
, using toolbarManageBehaviour
the enumeration.
6) Easily add up, down and finish buttons to keyboard UIToolbar UIView
classes, automatically using enableAutoToolbar
boolean values.
7) Enable/disable, the method of the next/previous button class, automatically use enableAutoToolbar
Boolean values.
8) Use the keyboard to set the distance text box keyboardDistanceFromTextField
.
9) Use the keyboard to touch the outside to shouldResignOnTouchOutside.
disable.
10) When the UITextView
height of the managed frame is too large, use the canAdjustTextView
setting to fit the screen.
11) Applies UITableView/UIScrollView
to UITextField/UITextView
12) You can input the sound when you click "Next/Previous/Finish".