最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS鍵盤如何添加隱藏鍵盤功能

 更新時(shí)間:2020年02月21日 12:51:36   作者:zyw658000  
這篇文章主要為大家詳細(xì)介紹了iOS鍵盤如何添加隱藏鍵盤功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iOS添加隱藏鍵盤功能的具體方法,供大家參考,具體內(nèi)容如下

鍵盤添加個(gè)隱藏鍵盤功能

使用方法:導(dǎo)入XMCustomKeyBoard.h
[XMCustomKeyBoard CancelableKeyboard:控件對象 ];
控件對象可以是UITextFiled,UITextView,UISearchBar 等一系列調(diào)用鍵盤輸入的類的實(shí)例

1.自定義個(gè)UIBarButtonItem,添加屬性editableView,editableView存儲需要添加隱藏鍵盤功能的那個(gè)控件

#import <UIKit/UIKit.h>

@interface XMCustomKeyBoardBtn : UIBarButtonItem
@property (strong, nonatomic) id editableView;

@end
#import "XMCustomKeyBoardBtn.h"

@implementation XMCustomKeyBoardBtn


@end

2.自定義個(gè)UIView,因?yàn)橹挥蠻IView的子類才可以添加進(jìn)keyWindow,想動態(tài)綁定這個(gè)類定義的方法,就必須讓這個(gè)類保持活躍。

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "XMCustomKeyBoardBtn.h"


@interface XMCustomKeyBoard : UIView

+ (void) CancelableKeyboard:(id) editableView;

+ (void) CancelableKeyboard:(id) editableView CustomButtonItem:(UIBarButtonItem *)btn;

@end

3.通過傳進(jìn)來的控件為其在鍵盤工具欄添加一個(gè)隱藏鍵盤的按鈕并動態(tài)綁定一個(gè)隱藏鍵盤的方法

#import "XMCustomKeyBoard.h"

@implementation XMCustomKeyBoard

+ (void) CancelableKeyboard:(id) editableView{
  XMCustomKeyBoard *custom = [[XMCustomKeyBoard alloc] initWithFrame:CGRectMake(0,-999,10,10)];
  [[UIApplication sharedApplication].keyWindow addSubview:custom];
  [editableView setInputAccessoryView:[self CancelableKeyboardToolBar:editableView addTarget:custom]];
}

+ (void) CancelableKeyboard:(id) editableView CustomButtonItem:(UIBarButtonItem *)btn {
  XMCustomKeyBoard *custom = [[XMCustomKeyBoard alloc] initWithFrame:CGRectMake(0,-10,10,10)];
  [[UIApplication sharedApplication].keyWindow addSubview:custom];
  [editableView setInputAccessoryView:[self CancelableKeyboardToolBar:editableView CustomButtonItem:btn addTarget:custom]];
}

+ (UIToolbar *)CancelableKeyboardToolBar:(id) editableView CustomButtonItem:(UIBarButtonItem *)btn addTarget:(id) target
{
  UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIApplication sharedApplication].keyWindow.frame), 40)];
  toolbar.backgroundColor = [UIColor lightGrayColor];
  
  UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:editableView action:@selector(onClick)];
  [button setWidth:[UIApplication sharedApplication].keyWindow.frame.size.width - btn.width];

  XMCustomKeyBoardBtn *button1 = (XMCustomKeyBoardBtn *)btn;
  
  button1.target = target;
  
  button1.action = @selector(CancelableKeyboard:);
  
  button1.editableView = editableView;
         
  [toolbar setItems:@[button,button1]];
  return toolbar;
}

+ (UIToolbar *)CancelableKeyboardToolBar:(id) editableView addTarget:(id) target
{
  UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIApplication sharedApplication].keyWindow.frame), 40)];
  toolbar.backgroundColor = [UIColor lightGrayColor];
  
  UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:editableView action:@selector(onClick)];
  [button setWidth:[UIApplication sharedApplication].keyWindow.frame.size.width - 50];

  XMCustomKeyBoardBtn *button1 = [[XMCustomKeyBoardBtn alloc] initWithTitle:@"隱藏鍵盤" style:UIBarButtonItemStyleBordered target:target action:@selector(CancelableKeyboard:)];
  
  button1.editableView = editableView;
         
  [button1 setWidth:50];
  [toolbar setItems:@[button,button1]];
  return toolbar;
}
-(void)CancelableKeyboard:(XMCustomKeyBoardBtn *) btn{
  [btn.editableView resignFirstResponder];
}
-(void) onClick{
  
}

@end

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。/p>

相關(guān)文章

最新評論

新泰市| 敦化市| 玉田县| 旌德县| 武陟县| 盐城市| 普兰店市| 瓦房店市| 大名县| 申扎县| 思南县| 阳东县| 西畴县| 黎平县| 建水县| 永丰县| 五河县| 台湾省| 常宁市| 阜平县| 石棉县| 肥西县| 宕昌县| 日土县| 平潭县| 类乌齐县| 米泉市| 沐川县| 集安市| 西和县| 桑日县| 保德县| 平乐县| 板桥市| 颍上县| 察雅县| 固安县| 汶上县| 新田县| 高台县| 云霄县|