IOS IM Development Recommendations (iii) Add a custom keyboard

Source: Internet
Author: User
Tags uikit

All kinds of mainstream IM, have their own definition of the keyboard: Emoji keyboard, select the picture of the keyboard. is actually a inputview.

First, we want to make sure that our keyboard is called by the input box. That is, we can set the inputview of a certain textview.

// Let the keyboard enter the edit state, replace the input source with the custom FV // FV is a custom UIView-(void) Callfacekeyboard: (UIButton *) button {    [Ktextview Becomefirstresponder];     = FV;    [Ktextview reloadinputviews];    [Ktextview.inputview Becomefirstresponder]; // set the custom keyboard to the first response }

Now this keyboard is paged out. Let's see how the keyboard is implemented.

1 . h2 #import<UIKit/UIKit.h>3 4 @interfaceFacekeyboardview:uiview5 //which expression was clicked ?6@property (nonatomic,copy)void(^Tapactionblock) (Nsinteger FaceID);7 //Send Message8@property (nonatomic,copy)void(^Sendemojiblock) ();9 Ten-(Instancetype) initWithFrame: (CGRect) frame Facearray: (Nsarray *) Facesarray; One @end A  -  -  the . M -  - #import "FaceKeyboardView.h" - @implementationfacekeyboardview{ +Nsmutablearray * DataArray;//an array of resources for emoticons -Uiscrollview * ScrollView;//The main selection page +UIButton * Sendbutton;//send button A } at //this must be implemented and set to Yes --(BOOL) Canbecomefirstresponder { -     returnYES; - } --(Instancetype) initWithFrame: (CGRect) frame Facearray: (Nsarray *) facesarray{ -Self =[Super Initwithframe:frame]; in     if(self) { -         //Set Send button to code ... +         //Set Body content - [self setscrollviewcontent:facesarray]; the     } *     returnSelf ; $ }Panax Notoginseng  -- (void) Setscrollviewcontent: (Nsarray *) Array { the     //Here's a view of each expression. Add a Click event + } A  the- (void) Touchthisview: (Uigesturerecognizer *) Tap { +     if([Tap.view Iskindofclass:[uiimageviewclass]]) -     if(self.) Tapactionblock) { $ Self . Tapactionblock (Tap.view.tag); $     } - } -  the- (void) Send: (UIButton *) button { -     if(self.) Sendemojiblock) {Wuyi Self . Sendemojiblock (); the     } - } Wu  - @end About             

Here, as long as the implementation of the block, the corresponding things to add to the TextView inside the good.

Of course, to turn it off, set TextView's Inputview to nil.

IOS IM Development Recommendations (iii) Add a custom keyboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.