Files
featherVoice/QXLive/Dynamic(语圈)/View/详情/QXDynamicCommentInputView.m

136 lines
5.1 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// QXDynamicCommentInputView.m
// QXLive
//
// Created by on 2025/6/4.
//
#import "QXDynamicCommentInputView.h"
@interface QXDynamicCommentInputView()<UITextFieldDelegate>
@property (nonatomic,strong)UICollectionView *collectionViwew;
2025-10-27 17:05:46 +08:00
@property (nonatomic,strong)UIView *bigBgView;
2025-08-08 10:49:36 +08:00
@property (nonatomic,strong)UIView *inputBgView;
@property (nonatomic,strong)UIView *inputShadowView;
@property (nonatomic,strong)UIButton *sendBtn;
@end
@implementation QXDynamicCommentInputView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.backgroundColor = [UIColor whiteColor];
self.sendBtn = [[UIButton alloc] init];
self.sendBtn.needEventInterval = 0.5;
[self.sendBtn setTitle:QXText(@"发送") forState:(UIControlStateNormal)];
self.sendBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.sendBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
self.sendBtn.backgroundColor = QXConfig.themeColor;
[self.sendBtn addRoundedCornersWithRadius:17.5];
[self.sendBtn addTarget:self action:@selector(sendAction) forControlEvents:(UIControlEventTouchUpInside)];;
[self addSubview:self.sendBtn];
[self.sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-16);
make.top.mas_equalTo(8);
make.height.mas_equalTo(35);
make.width.mas_equalTo(80);
}];
self.inputBgView = [[UIView alloc] init];
self.inputBgView.backgroundColor = RGB16(0xF5F5F5);
[self.inputBgView addRoundedCornersWithRadius:8];
[self addSubview:self.inputBgView];
[self.inputBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.right.equalTo(self.sendBtn.mas_left).offset(-12);
make.centerY.equalTo(self.sendBtn);
make.height.mas_equalTo(35);
}];
self.textField = [[UITextField alloc] init];
self.textField.font = [UIFont systemFontOfSize:14];
self.textField.textColor = QXConfig.textColor;
2025-10-27 17:05:46 +08:00
self.textField.returnKeyType = UIReturnKeySend;
2025-08-08 10:49:36 +08:00
self.textField.delegate = self;
[self.textField addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
[self.inputBgView addSubview:self.textField];
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(10);
make.right.mas_equalTo(-10);
make.top.bottom.equalTo(self.inputBgView);
}];
self.inputShadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 4)];
self.inputShadowView.backgroundColor = [UIColor whiteColor];
self.inputShadowView.layer.shadowColor = [UIColor grayColor].CGColor;
self.inputShadowView.layer.shadowOpacity = 0.2;
self.inputShadowView.layer.shadowOffset = CGSizeMake(0, -2);
self.inputShadowView.layer.shadowRadius = 2;
self.inputShadowView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.inputShadowView.bounds cornerRadius:self.inputShadowView.layer.cornerRadius].CGPath;
self.inputShadowView.layer.cornerRadius = 2;
self.inputShadowView.layer.masksToBounds = NO;
[self addSubview:self.inputShadowView];
// self.inputShadowView.layer.shadowColor = [UIColor grayColor].CGColor;
// self.inputShadowView.layer.shadowOpacity = 0.5;
// self.inputShadowView.layer.shadowOffset = CGSizeMake(0, -2);
//// self.inputShadowView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:0].CGPath;
// self.inputShadowView.layer.masksToBounds = NO;
}
-(void)textDidChange:(UITextField*)textField{
if (textField.text.length>50) {
showToast(@"评论不得超过50个字符");
textField.text = [textField.text substringToIndex:50];
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
2025-10-27 17:05:46 +08:00
if (self.textField.text.length == 0) {
showToast(@"内容不能为空");
return NO;
}
2025-08-08 10:49:36 +08:00
[textField resignFirstResponder];
2025-10-27 17:05:46 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickSendWithText:model:)]) {
[self.delegate didClickSendWithText:self.textField.text model:self.model];
}
2025-08-08 10:49:36 +08:00
return YES;
}
2025-10-20 09:43:10 +08:00
-(void)textFieldDidEndEditing:(UITextField *)textField{
if (self.delegate && [self.delegate respondsToSelector:@selector(didResignFirstResponder)]) {
[self.delegate didResignFirstResponder];
}
}
2025-10-27 17:05:46 +08:00
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if (self.delegate && [self.delegate respondsToSelector:@selector(didBecomeFirstResponder)]) {
[self.delegate didBecomeFirstResponder];
}
}
2025-08-08 10:49:36 +08:00
-(void)setModel:(QXDynamicCommentListModel *)model{
_model = model;
}
-(void)inputBecomeFirstResponder{
[self.textField becomeFirstResponder];
}
-(void)sendAction{
2025-10-27 17:05:46 +08:00
if (self.textField.text.length == 0) {
showToast(@"内容不能为空");
return;
}
2025-08-08 10:49:36 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickSendWithText:model:)]) {
[self.delegate didClickSendWithText:self.textField.text model:self.model];
}
}
@end