add flying commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// GiGaCommentView.h
|
||||
// LXAnimationTest
|
||||
//
|
||||
// Created by lianxiang on 2018/8/14.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "GiGaCommentModel.h"
|
||||
@interface GiGaCommentView : UIView
|
||||
@property(nonatomic,strong) GiGaCommentModel *msgModel;
|
||||
-(instancetype)initWithMsgModel:(GiGaCommentModel *)model height:(CGFloat)height;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// GiGaCommentView.m
|
||||
// LXAnimationTest
|
||||
//
|
||||
// Created by lianxiang on 2018/8/14.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaCommentView.h"
|
||||
#import "Masonry.h"
|
||||
@interface GiGaCommentView()
|
||||
@property(nonatomic,strong) UILabel *userName;
|
||||
@property(nonatomic,strong) UIImageView *userAvtar;
|
||||
@property(nonatomic,strong) UILabel *msg;
|
||||
@end
|
||||
|
||||
@implementation GiGaCommentView
|
||||
|
||||
-(instancetype)initWithMsgModel:(GiGaCommentModel *)model height:(CGFloat)height{
|
||||
|
||||
if (self = [super init]) {
|
||||
self.frame = CGRectMake(0, 0, 0, height);
|
||||
_msgModel = model;
|
||||
//self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
|
||||
self.backgroundColor = [UIColor redColor];
|
||||
[self initUI];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)layoutIfNeeded{
|
||||
|
||||
}
|
||||
- (void)layoutSubviews{
|
||||
|
||||
}
|
||||
|
||||
-(void)initUI{
|
||||
|
||||
UIImageView *avatar = [[UIImageView alloc] init];
|
||||
avatar.image = [UIImage imageNamed:@"home_login_qq_color"];
|
||||
//avatar.frame = CGRectMake(3, 3, self.frame.size.height - 6, self.frame.size.height - 6);
|
||||
avatar.layer.masksToBounds = YES;
|
||||
avatar.layer.cornerRadius = 15;
|
||||
[self addSubview:avatar];
|
||||
avatar.image = [UIImage imageNamed:_msgModel.userAvatar];
|
||||
self.userAvtar = avatar;
|
||||
[self.userAvtar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(30);
|
||||
make.height.mas_equalTo(30);
|
||||
make.left.mas_equalTo(self.mas_left).mas_offset(3);
|
||||
make.top.mas_equalTo(self.mas_top).mas_offset(3);
|
||||
|
||||
}];
|
||||
|
||||
UILabel *namelabel = [[UILabel alloc] init];
|
||||
namelabel.font = [UIFont systemFontOfSize:14];
|
||||
namelabel.textColor = [UIColor blackColor];
|
||||
//namelabel.frame= CGRectMake(CGRectGetMaxX(avatar.frame) + 5, 4, namelabel.frame.size.width, namelabel.frame.size.height);
|
||||
namelabel.text = _msgModel.userName;
|
||||
[namelabel sizeToFit];
|
||||
self.userName = namelabel;
|
||||
[self addSubview:self.userName];
|
||||
[self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
|
||||
make.left.mas_equalTo(self.userAvtar.mas_right).mas_offset(3);
|
||||
make.top.mas_equalTo(self.mas_top).mas_offset(10);
|
||||
|
||||
}];
|
||||
|
||||
UILabel *msglabel = [[UILabel alloc] init];
|
||||
msglabel.font = [UIFont systemFontOfSize:13];
|
||||
msglabel.textColor = [UIColor blackColor];
|
||||
|
||||
//msglabel.frame= CGRectMake(namelabel.frame.origin.x, CGRectGetMaxY(avatar.frame) - msglabel.frame.size.height - namelabel.frame.origin.y, msglabel.frame.size.width, msglabel.frame.size.height);
|
||||
msglabel.text = _msgModel.msg;
|
||||
self.msg = msglabel;
|
||||
[msglabel sizeToFit];
|
||||
[self addSubview:self.msg];
|
||||
[self.msg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
|
||||
make.top.mas_equalTo(self.userAvtar.mas_bottom).mas_offset(3);
|
||||
make.left.mas_equalTo(self.mas_left).mas_offset(5);
|
||||
|
||||
|
||||
}];
|
||||
|
||||
float width = msglabel.frame.size.width > namelabel.frame.size.width ? msglabel.frame.size.width:namelabel.frame.size.width ;
|
||||
|
||||
self.frame = CGRectMake(0, 0, namelabel.frame.origin.x + 10 + width, self.frame.size.height);
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// GiGaFlyingCommitInputView.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/28.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface GiGaFlyingCommitInputView : UIView
|
||||
|
||||
@property (nonatomic, copy) void (^SendCommentHandler)(NSString *content);
|
||||
@property (nonatomic, copy) NSString *palceholderText;
|
||||
-(void)setPalceholderText:(NSString *)palceholderText;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,169 @@
|
||||
//
|
||||
// GiGaFlyingCommitInputView.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/28.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaFlyingCommitInputView.h"
|
||||
@interface GiGaFlyingCommitInputView()<UITextFieldDelegate>
|
||||
@property(nonatomic,strong) UIView *commitInputView;
|
||||
@property(nonatomic,strong) UITextField * inputTextField;
|
||||
@end
|
||||
|
||||
@implementation GiGaFlyingCommitInputView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
|
||||
// self.backgroundColor = [UIColor blackColor];
|
||||
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
|
||||
// UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissSelfViewTap)];
|
||||
// [self addGestureRecognizer:tap];
|
||||
|
||||
[self creatInputView];
|
||||
[self bringSubviewToFront:_commitInputView];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)creatInputView{
|
||||
|
||||
UIView *commitView =[[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height - 60, self.bounds.size.width, 60)];
|
||||
// commitView.frame = CGRectMake(0, self.frame.size.height-commitView.frame.size.height, self.frame.size.width, commitView.frame.size.height);
|
||||
self.commitInputView = commitView;
|
||||
self.commitInputView.backgroundColor = [UIColor redColor];
|
||||
[self addSubview:self.commitInputView];
|
||||
|
||||
UIButton *sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
CGFloat topMargin = 5;
|
||||
CGFloat leftMargin = 10;
|
||||
sendBtn.frame = CGRectMake(self.frame.size.width - leftMargin - 60,topMargin,60,40);
|
||||
[sendBtn addTarget:self action:@selector(sendBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[sendBtn setTitle:@"发送" forState:UIControlStateNormal];
|
||||
[sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
sendBtn.backgroundColor = [UIColor purpleColor];
|
||||
sendBtn.layer.masksToBounds = YES;
|
||||
sendBtn.layer.cornerRadius = 4;
|
||||
[commitView addSubview:sendBtn];
|
||||
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 5,self.frame.size.width - sendBtn.frame.size.width - 10*2 - 5, 30)];
|
||||
textField.backgroundColor = [UIColor lightGrayColor];
|
||||
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
||||
textField.delegate = self;
|
||||
[commitView addSubview:textField];
|
||||
self.inputTextField = textField;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(keyboardWillHide:)
|
||||
name:UIKeyboardWillHideNotification
|
||||
object:nil];
|
||||
|
||||
}
|
||||
|
||||
-(void)setPalceholderText:(NSString *)palceholderText
|
||||
{
|
||||
_palceholderText = palceholderText;
|
||||
}
|
||||
|
||||
-(void)dismissSelfViewTap{
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
|
||||
-(void)sendBtnAction:(UIButton *)btn{
|
||||
|
||||
[self sendCommend];
|
||||
}
|
||||
|
||||
-(void)sendCommend{
|
||||
|
||||
if (self.inputTextField.text.length > 200) {
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:@"The comments should not exceed 200 words" duration:1 position:CSToastPositionCenter];
|
||||
return;
|
||||
}
|
||||
if (self.inputTextField.text.length == 0) {
|
||||
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:@"Comment content cannot be empty" duration:1 position:CSToastPositionCenter];
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.SendCommentHandler) {
|
||||
self.SendCommentHandler(self.inputTextField.text);
|
||||
}
|
||||
|
||||
[self dismissKeyboard];
|
||||
|
||||
}
|
||||
|
||||
- (void)dismissKeyboard
|
||||
{
|
||||
if ([self.inputTextField becomeFirstResponder]) {
|
||||
[self.inputTextField resignFirstResponder];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
|
||||
{
|
||||
if (textField ==self.inputTextField) {
|
||||
textField.placeholder = _palceholderText;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
|
||||
|
||||
if (textField ==self.inputTextField) {
|
||||
[self sendCommend];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)keyboardWillShow:(NSNotification*)notification {
|
||||
|
||||
// get keyboard size and loctaion
|
||||
CGRect keyboardBounds;
|
||||
[[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
|
||||
NSNumber *duration = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
|
||||
NSNumber *curve = [notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
|
||||
|
||||
// Need to translate the bounds to account for rotation.
|
||||
keyboardBounds = [self convertRect:keyboardBounds toView:nil];
|
||||
|
||||
// get a rect for the textView frame
|
||||
CGRect commentInputViewFrame = self.commitInputView.frame;
|
||||
commentInputViewFrame.origin.y = self.bounds.size.height - (keyboardBounds.size.height + commentInputViewFrame.size.height);
|
||||
|
||||
// animations settings
|
||||
[UIView beginAnimations:nil context:NULL];
|
||||
[UIView setAnimationBeginsFromCurrentState:YES];
|
||||
[UIView setAnimationDuration:[duration doubleValue]];
|
||||
[UIView setAnimationCurve:[curve intValue]];
|
||||
|
||||
// set views with new info
|
||||
self.commitInputView.frame = commentInputViewFrame;
|
||||
|
||||
[UIView commitAnimations];
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void) keyboardWillHide:(NSNotification *)note
|
||||
{
|
||||
self.commitInputView.frame = CGRectMake(0, self.bounds.size.height - 60, self.bounds.size.width, 60);
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
self.commitInputView = nil;
|
||||
self.inputTextField= nil;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user