| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //
- // SendMessageView.m
- // IBOSS
- //
- // Created by guan hong hou on 16/1/18.
- // Copyright © 2016年 elongtian. All rights reserved.
- //
- #import "SendMessageView.h"
- @interface SendMessageView () <UITextFieldDelegate>
- @property (nonatomic, strong) UITextField *inputTextField;
- @property (nonatomic, strong) UIButton *sendBtn;
- @property (nonatomic)CGFloat offset;
- @end
- @implementation SendMessageView
- #pragma mark -公有方法
- //初始化发送消息布局
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboardWillShow:)
- name:UIKeyboardWillShowNotification
- object:nil];
-
-
- }
- return self;
- }
- #pragma mark -委托回调方法
- //输入框回车事件
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- if ([self.sendMessageDelegate respondsToSelector:@selector(didSendMessage:albumInputView:)]) {
- [self.sendMessageDelegate didSendMessage:textField.text albumInputView:self];
- }
- return YES;
- }
- #pragma mark -私有方法
- //初始化发送消息视图
- -(void)setHintMessage:(NSString*)hintMessage view:(UIView*) view{
- CGRect inputTextRect=CGRectMake(10, 13, CGRectGetWidth([[UIScreen mainScreen] bounds]) - 60,24);
- if (!_inputTextField) {
- _inputTextField = [[UITextField alloc] initWithFrame:inputTextRect];
-
- _inputTextField.placeholder=hintMessage;
- _inputTextField.delegate = self;
- _inputTextField.returnKeyType = UIReturnKeySend;
- _inputTextField.borderStyle = UITextBorderStyleRoundedRect;
- [self addSubview:_inputTextField];
- [_inputTextField becomeFirstResponder];
- }
- if(!_sendBtn){
- _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_sendBtn addTarget:self action:@selector(sendData)
- forControlEvents:UIControlEventTouchUpInside];
- _sendBtn.frame = CGRectMake(CGRectGetMaxX(inputTextRect)+3,13,40, 24);
- [_sendBtn setTitle:@"发送" forState:UIControlStateNormal];
- [_sendBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
- [self addSubview:_sendBtn];
- }
-
- }
- //键盘弹出通知
- -(void)keyboardWillShow:(NSNotification *)note
- {
- CGFloat kbHeight = [[note.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
- //设置高度,根据父控件的高度-键盘高度-输入框的高度,在外围已经将父控件的高度设置成到屏幕底部
- self.frame = CGRectMake(0.0f,self.superview.frame.size.height-kbHeight-50, self.frame.size.width,self.frame.size.height);
- }
- //隐藏键盘
- - (void)finishSendMessage {
- self.inputTextField.text = nil;
- [ self.inputTextField resignFirstResponder];
- }
- //发送消息方法
- -(void)sendData{
- NSString *sendInfo=_inputTextField.text;
- [self.sendMessageDelegate didSendMessage:sendInfo albumInputView:self];
-
- }
- @end
|