ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 网络编程 >> IOS开发 >> iOS 键盘自适应(IQKeyboardManager)使用小结

iOS 键盘自适应(IQKeyboardManager)使用小结

来源:网络整理     时间:2015-03-11     关键词:

本篇文章主要介绍了"iOS 键盘自适应(IQKeyboardManager)使用小结",对于IOS开发感兴趣的同学可以参考一下: IQKeyboardManager Github地址经常在开发一个应用程序,我们遇到了一个问题,iPhone的键盘上滑覆盖的UITextField / UITe...


IQKeyboardManager Github地址

经常在开发一个应用程序,我们遇到了一个问题,iPhone的键盘上滑覆盖的UITextField / UITextViewIQKeyboardManager可以防止键盘滑动问题和覆盖UITextField / UITextView无需你输入任何代码,不需要额外的设置要求。使用IQKeyboardManager你只需要添加源文件到你的项目。

主要特点

1)无代码
2)自动工作
3)没有更多的UIScrollView
4)没有更多的子类
5)没有更多的手动工作
6)没有更多#imports

截图


IQKeyboardManager 支持 CocoaPods

pod ‘IQKeyboardManager’

管理

UINavigationBar

如果你不使用storyboardxib创造你的视图。你需要重写-(void)UIViewController loadview方法,需要设置一个UIScrollView实例self.view

-(void)loadView  


UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.view = scrollView;
}

为某一个ViewController禁用IQKeyboardManager

如果你想在某个 viewcontroller 禁用 IQKeyboardManager 你应该在 ViewDidAppear 中禁用IQKeyboardManager,而在ViewWillDisappear启用它
代码:

 #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 


键盘的回车键处理

1)创建一个实例变量实例化IQKeyboardReturnKeyHandlerViewControllerviewDidLoad

代码:

	@implementationViewController  {  IQKeyboardReturnKeyHandler *returnKeyHandler;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
}

改变键盘上的返回键。

设置实例变量为零的dealloc方法
-(void)dealloc {
    returnKeyHandler = nil;
}

UIToolbar(IQToolbar)

1)如果你不想添加一个特定的自动工具栏在键盘上方,应该添加一个类作为它的工具栏
textField.inputAccessoryView = [[UIView alloc] init];
2)如果你需要自己控制上/下/完成按钮,那么应该使用UIView类的方法,创建你的文本框工具栏。

代码:

-(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
                
                
                

以上就介绍了iOS 键盘自适应(IQKeyboardManager)使用小结,包括了方面的内容,希望对IOS开发有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_117701.html

相关图片

相关文章