亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

鍵盤添加個隱藏鍵盤功能

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

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

#import <UIKit/UIKit.h>

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

@end
#import "XMCustomKeyBoardBtn.h"

@implementation XMCustomKeyBoardBtn


@end

2.自定義個UIView,因為只有UIView的子類才可以添加進keyWindow,想動態(tài)綁定這個類定義的方法,就必須讓這個類保持活躍。

#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.通過傳進來的控件為其在鍵盤工具欄添加一個隱藏鍵盤的按鈕并動態(tài)綁定一個隱藏鍵盤的方法

#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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。/p>

相關(guān)文章

  • 詳解iOS應用使用Storyboard布局時的IBOutlet與IBAction

    詳解iOS應用使用Storyboard布局時的IBOutlet與IBAction

    這篇文章主要介紹了iOS應用使用Storyboard布局時的IBOutlet與IBAction,文中還附帶講解了為什么IBOutlet屬性是weak的,需要的朋友可以參考下
    2016-04-04
  • iOS開發(fā)創(chuàng)建frame實現(xiàn)window窗口view視圖示例

    iOS開發(fā)創(chuàng)建frame實現(xiàn)window窗口view視圖示例

    這篇文章主要為大家介紹了iOS開發(fā)創(chuàng)建frame實現(xiàn)window窗口view視圖示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-05-05
  • iOS UILabel根據(jù)內(nèi)容自動調(diào)整高度

    iOS UILabel根據(jù)內(nèi)容自動調(diào)整高度

    這篇文章主要為大家詳細介紹了iOS UILabel根據(jù)內(nèi)容自動調(diào)整高度,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • iOS實現(xiàn)秒殺活動倒計時

    iOS實現(xiàn)秒殺活動倒計時

    這篇文章主要為大家詳細介紹了iOS實現(xiàn)秒殺活動倒計時,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • 基于iOS實現(xiàn)倒影效果

    基于iOS實現(xiàn)倒影效果

    這篇文章主要為大家詳細介紹了基于iOS實現(xiàn)倒影效果的相關(guān)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵

    iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵

    這篇文章主要介紹了iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵 的相關(guān)資料,需要的朋友可以參考下
    2016-08-08
  • iOS消息遠程推送通知

    iOS消息遠程推送通知

    這篇文章主要為大家詳細介紹了iOS消息遠程推送通知代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • iOS Touch ID指紋識別技術(shù)簡介

    iOS Touch ID指紋識別技術(shù)簡介

    這篇文章主要為大家詳細介紹了iOS Touch ID指紋識別技術(shù),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • iOS APP簽名機制原理詳解

    iOS APP簽名機制原理詳解

    這篇文章主要介紹了iOS APP簽名機制原理詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • iOS NSDate中關(guān)于夏令時的坑

    iOS NSDate中關(guān)于夏令時的坑

    這篇文章主要給大家介紹了關(guān)于iOS NSDate中夏令時的坑,以及iOS 時間字符串&NSDate&時間戳 相互轉(zhuǎn)換的相關(guān)內(nèi)容,分享出來供大家參考學習,需要的朋友可以參考借鑒,下面隨小編來一起學習學習吧
    2018-08-08

最新評論