iOS IM開發建議(三)添加一個自訂鍵盤,iosim

來源:互聯網
上載者:User

iOS IM開發建議(三)添加一個自訂鍵盤,iosim

  各類的主流IM,都有自己定義的鍵盤:有表情鍵盤,選圖片的鍵盤。其實都是一個inputView。  

  首先,我們要確定,我們的鍵盤是輸入框調用的。也就是,我們可以設定的是某一個textView的inputView。

// 讓鍵盤進入編輯狀態,替換輸入源為自訂的fv// fv 是一個自訂的UIView- (void)callFaceKeyBoard:(UIButton *)button {    [ktextView becomeFirstResponder];    ktextView.inputView = fv;    [ktextView reloadInputViews];    [ktextView.inputView becomeFirstResponder];// 把自訂鍵盤設定為第一響應}

  現在這個鍵盤是調出來了。那我們看看鍵盤怎麼實現。

 1 .h 2 #import <UIKit/UIKit.h> 3  4 @interface FaceKeyboardView : UIView 5 // 點擊了哪一個表情 6 @property(nonatomic,copy)void (^TapActionBlock)(NSInteger faceID); 7 // 發送資訊 8 @property(nonatomic,copy)void (^SendEmojiBlock)(); 9 10 - (instancetype)initWithFrame:(CGRect)frame faceArray:(NSArray *)facesArray;11 @end12 13 14 15 .m16 17 #import "FaceKeyboardView.h"18 @implementation FaceKeyboardView{19     NSMutableArray * dataArray;// 表情的資源數組20     UIScrollView * scrollView;// 主的選折頁面21     UIButton * sendButton;// 發送按鈕22 }23 // 這個一定要實現 而且要設定YES24 - (BOOL)canBecomeFirstResponder {25     return YES;26 }27 - (instancetype)initWithFrame:(CGRect)frame faceArray:(NSArray *)facesArray{28     self = [super initWithFrame:frame];29     if(self) {30         //設定發送按鈕31                code...32         //設定主體內容33         [self setScrollViewContent:facesArray];34     }35     return self;36 }37 38 - (void)setScrollViewContent:(NSArray *)array {39     //這裡布置好每一個表情的view 添加點擊事件40 }41 42 - (void)touchThisView:(UIGestureRecognizer *)tap {43     if([tap.view isKindOfClass:[UIImageView class]])44     if(self.TapActionBlock) {45         self.TapActionBlock(tap.view.tag);46     }47 }48 49 - (void)send:(UIButton *)button {50     if(self.SendEmojiBlock){51         self.SendEmojiBlock();52     }53 }54 55 @end56             

  到這裡,只要實現block,把對應的東西添加到textView裡面就好了。

  當然要關掉它的話,就把textView的inputView設定為nil。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.