99热99这里只有精品6国产,亚洲中文字幕在线天天更新,在线观看亚洲精品国产福利片 ,久久久久综合网

歡迎加入QQ討論群258996829
麥子學(xué)院 頭像
蘋果6袋
6
麥子學(xué)院

ios中如何自定義數(shù)字鍵盤

發(fā)布時(shí)間:2017-01-16 11:09  回復(fù):0  查看:3167   最后回復(fù):2017-01-16 11:09  

本文和大家分享的主要是ios開發(fā)中自定義數(shù)字鍵盤的相關(guān)知識(shí),希望對(duì)大家有所幫助,一起來看看吧。

  第一種方式: 在獲得鍵盤彈出通知時(shí),在鍵盤的那個(gè) UIView 上添加一個(gè)自定義的 UIButto。

  #define KEY_WIDTH 106

  #define KEY_HEIGHT 53

  #pragma mark – 處理 TextField 響應(yīng)事件

  – ( void )editingDidBegin:( UITextField *)textF {

  [ self . textF becomeFirstResponder ];

  }

  //3. 實(shí)現(xiàn)通知處理

  – ( void )handleKeyboardWillHide:( NSNotification *)notification

  {

  if ( doneInKeyboardButton . superview )

  {

  [ doneInKeyboardButton removeFromSuperview ];

  }

  }

  – ( void )handleKeyboardDidShow:( NSNotification *)notification

  {

  NSDictionary *info = [notification userInfo ];

  CGSize kbSize = [[info objectForKey : UIKeyboardFrameEndUserInfoKey ] CGRectValue ]. size ;

  CGFloat normalKeyboardHeight = kbSize. height ;

  int cnt = [[ UIApplication sharedApplication ] windows ]. count ;

  UIWindow * tempWindow = [[[ UIApplication sharedApplication ] windows ] objectAtIndex :cnt- 1 ];

  // create custom button

  if ( doneInKeyboardButton == nil )

  {

  doneInKeyboardButton = [ UIButton buttonWithType : UIButtonTypeCustom ];

  doneInKeyboardButton . frame = CGRectMake ( 18 , tempWindow. frame . size . height – 53 , 106 , 53 );

  doneInKeyboardButton . adjustsImageWhenHighlighted = NO ;

  [ doneInKeyboardButton setImage :[ UIImage imageNamed : @”done.png” ] forState :UIControlStateNormal ];

  [ doneInKeyboardButton setImage :[ UIImage imageNamed : @”done.png” ] forState :UIControlStateHighlighted ];

  [ doneInKeyboardButton addTarget : self action : @selector (finishAction) forControlEvents : UIControlEventTouchUpInside ];

  }

  // locate keyboard view

  if ( doneInKeyboardButton . superview == nil )

  {

  // 注意這里直接加到 window 

  [tempWindow addSubview : doneInKeyboardButton ];

  }

  }

  #pragma mark – 處理視圖響應(yīng)事件

  – ( void )touchesBegan:( NSSet *)touches withEvent:( UIEvent *)event {

  [ self . textF resignFirstResponder ];

  }

  -( void )viewWillAppear:( BOOL )animated

  {

  [ super viewWillAppear :animated];

  //1. 先注冊(cè)通知 [[ NSNotificationCenter defaultCenter ] addObserver : self selector :@selector (handleKeyboardDidShow:) name : UIKeyboardDidShowNotification object :nil ];

  [[ NSNotificationCenter defaultCenter ] addObserver : self selector : @selector (handleKeyboardWillHide:) name : UIKeyboardWillHideNotification object : nil ];

  }

  //2. 在 dealloc 中反注冊(cè)通知

  -( void )dealloc

  {

  [[ NSNotificationCenter defaultCenter ] removeObserver : self ];

  }

  第二種方法:自己寫一個(gè)鍵盤。:laughing:

 

來源:海之飛燕

您還未登錄,請(qǐng)先登錄

熱門帖子

最新帖子

?