IOS IM development suggestion (3) Add a custom keyboard, iosim
All types of mainstream IM have their own defined keyboards: emoticon keyboards and image keyboards. It is actually an inputView.
First, make sure that our keyboard is called by the input box. That is, we can set the inputView of a textView.
// Let the keyboard enter the editing status, replace the input source with the custom fv // fv is a custom UIView-(void) callFaceKeyBoard :( UIButton *) button {[ktextView becomeFirstResponder]; ktextView. inputView = fv; [ktextView reloadInputViews]; [ktextView. inputView becomeFirstResponder]; // set the custom keyboard to the first response}
Now this keyboard is called up. Let's see how the keyboard works.
1. h 2 # import <UIKit/UIKit. h> 3 4 @ interface FaceKeyboardView: UIView 5 // The emoticons you clicked. 6 @ property (nonatomic, copy) void (^ TapActionBlock) (NSInteger faceID ); 7 // send message 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; // resource array of emoticon 20 UIScrollView * scrollView; // The main tab page 21 UIButton * sendButton; // send button 22} 23 // This must be implemented and YES24-(BOOL) canBecomeFirstResponder {25 return YES; 26} 27-(instancetype) initWithFrame :( CGRect) must be set) frame faceArray :( NSArray *) facesArray {28 self = [super initWithFrame: frame]; 29 if (self) {30 // set the sending button 31 code... 32 // set subject content 33 [self setScrollViewContent: facesArray]; 34} 35 return self; 36} 37 38-(void) setScrollViewContent :( NSArray *) array {39 // The view for each expression is arranged here. Add Click Event 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
Here, you only need to implement the block and add the corresponding items to the textView.
Of course, if you want to disable it, set inputView of textView to nil.