250 lines
10 KiB
Objective-C
250 lines
10 KiB
Objective-C
//
|
||
// QXDirectSetScaleView.m
|
||
// IsLandVoice
|
||
//
|
||
// Created by 启星 on 2025/3/6.
|
||
//
|
||
|
||
#import "QXDirectSetScaleView.h"
|
||
#import "QXMineNetwork.h"
|
||
|
||
@interface QXDirectSetScaleView()<UITextFieldDelegate>
|
||
@property (nonatomic,strong)UIView *bgView;
|
||
@property (nonatomic,strong)UILabel *titleLabel;
|
||
@property (nonatomic,strong)UIButton *closeBtn;
|
||
@property (nonatomic,strong)UIView *scaleBGView;
|
||
@property (nonatomic,strong)UITextField *textField;
|
||
@property (nonatomic,strong)UILabel *unitLabel;
|
||
|
||
@property (nonatomic,strong)UIButton *coinBtn;
|
||
@property (nonatomic,strong)UILabel *timeLabel;
|
||
|
||
@property (nonatomic,strong)UILabel *messageLabel;
|
||
@property (nonatomic,strong)UIButton *commitBtn;
|
||
|
||
|
||
@end
|
||
|
||
@implementation QXDirectSetScaleView
|
||
|
||
- (instancetype)initWithFrame:(CGRect)frame
|
||
{
|
||
self = [super initWithFrame:frame];
|
||
if (self) {
|
||
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||
[self createViews];
|
||
}
|
||
return self;
|
||
}
|
||
-(void)createViews{
|
||
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
|
||
// self.bgView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AUTO_CEIL_WIETH(275))/2.0, (SCREEN_HEIGHT-AUTO_CEIL_WIETH(300))/2.0, AUTO_CEIL_WIETH(275), AUTO_CEIL_WIETH(300))];
|
||
self.bgView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-ScaleWidth(275))/2.0, -self.height, ScaleWidth(275), ScaleWidth(300))];
|
||
self.bgView.backgroundColor = [UIColor whiteColor];
|
||
self.bgView.layer.masksToBounds = YES;
|
||
self.bgView.layer.cornerRadius = 16;
|
||
[self addSubview:self.bgView];
|
||
|
||
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 12, self.bgView.width, 24)];
|
||
self.titleLabel.text = @"请设置收益比例";
|
||
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
||
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
||
self.titleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
||
[self.bgView addSubview:self.titleLabel];
|
||
|
||
self.closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.width-50, 0, 50, 50)];
|
||
[self.closeBtn setImage:[UIImage imageNamed:@"wallet_close"] forState:(UIControlStateNormal)];
|
||
[self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
|
||
[self.bgView addSubview:self.closeBtn];
|
||
|
||
self.scaleBGView = [[UIView alloc] initWithFrame:CGRectMake(12, self.titleLabel.bottom+35, self.bgView.width-12*2, 44)];
|
||
self.scaleBGView.backgroundColor = [UIColor colorWithHexString:@"#EFF2F8"];
|
||
self.scaleBGView.layer.masksToBounds = YES;
|
||
self.scaleBGView.layer.cornerRadius = 11;
|
||
[self.bgView addSubview:self.scaleBGView];
|
||
|
||
self.unitLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.scaleBGView.right-12-35, 0, 35, self.scaleBGView.height)];
|
||
self.unitLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
||
self.unitLabel.text = @"%";
|
||
self.unitLabel.font = [UIFont boldSystemFontOfSize:16];
|
||
[self.scaleBGView addSubview:self.unitLabel];
|
||
|
||
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(12, 0, self.unitLabel.left-24, 44)];
|
||
self.textField.placeholder = @"请设置收益比例";
|
||
self.textField.returnKeyType = UIReturnKeyDone;
|
||
self.textField.keyboardType = UIKeyboardTypeNumberPad;
|
||
self.textField.delegate = self;
|
||
self.textField.font = [UIFont boldSystemFontOfSize:16];
|
||
[self.textField addTarget:self action:@selector(textDidChange:) forControlEvents:(UIControlEventValueChanged)];
|
||
self.textField.textColor = [UIColor colorWithHexString:@"#333333"];
|
||
[self.scaleBGView addSubview:self.textField];
|
||
|
||
self.messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(18, self.scaleBGView.bottom+35, self.bgView.width-36, 90)];
|
||
self.messageLabel.numberOfLines = 0;
|
||
self.messageLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
||
self.messageLabel.text = @"设置后主持人收益为主持期间房间收益的该百分比";
|
||
self.messageLabel.font = [UIFont systemFontOfSize:13];
|
||
[self.bgView addSubview:self.messageLabel];
|
||
|
||
self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, self.scaleBGView.bottom+12, 50, 18)];
|
||
self.timeLabel.numberOfLines = 0;
|
||
self.timeLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
||
self.timeLabel.font = [UIFont systemFontOfSize:13];
|
||
self.timeLabel.hidden = YES;
|
||
[self.bgView addSubview:self.timeLabel];
|
||
|
||
self.coinBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 18)];
|
||
self.coinBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeading;
|
||
[self.coinBtn setImage:[UIImage imageNamed:@"room_upseat_coin"] forState:(UIControlStateNormal)];
|
||
[self.coinBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:(UIControlStateNormal)];
|
||
self.coinBtn.titleLabel.font = [UIFont systemFontOfSize:13];
|
||
self.coinBtn.hidden = YES;
|
||
[self.bgView addSubview:self.coinBtn];
|
||
|
||
self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, self.bgView.height-12-42, self.bgView.width-100, 42)];
|
||
[self.commitBtn setTitle:@"确定" forState:(UIControlStateNormal)];
|
||
[self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
|
||
self.commitBtn.backgroundColor = QXConfig.themeColor;
|
||
self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:15];
|
||
[self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
self.commitBtn.layer.masksToBounds = YES;
|
||
self.commitBtn.layer.cornerRadius = 21;
|
||
self.commitBtn.needEventInterval = 0.3;
|
||
[self.bgView addSubview:self.commitBtn];
|
||
|
||
}
|
||
-(void)setIsGiveCoin:(BOOL)isGiveCoin{
|
||
_isGiveCoin = isGiveCoin;
|
||
self.titleLabel.text = @"您正在进行转币操作";
|
||
self.textField.placeholder = @"请输入金币数量";
|
||
self.messageLabel.hidden = YES;
|
||
self.unitLabel.hidden = YES;
|
||
self.textField.keyboardType = UIKeyboardTypeNumberPad;
|
||
}
|
||
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
||
[self endEditing:YES];
|
||
}
|
||
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
|
||
[textField resignFirstResponder];
|
||
return YES;
|
||
}
|
||
-(void)textFieldDidBeginEditing:(UITextField *)textField{
|
||
[UIView animateWithDuration:0.15 animations:^{
|
||
self.bgView.y = (SCREEN_HEIGHT-ScaleWidth(300))/2.0-100;
|
||
}];
|
||
}
|
||
-(void)textFieldDidEndEditing:(UITextField *)textField{
|
||
[UIView animateWithDuration:0.15 animations:^{
|
||
self.bgView.y = (SCREEN_HEIGHT-ScaleWidth(300))/2.0;
|
||
}];
|
||
}
|
||
|
||
-(void)commitAction{
|
||
if (self.isGiveCoin) {
|
||
if (self.textField.text.longValue == 0) {
|
||
showToast(@"请输入金币数量");
|
||
return;
|
||
}
|
||
MJWeakSelf
|
||
[QXMineNetwork giveCoinWithUserId:self.userId coin:self.textField.text successBlock:^(NSDictionary * _Nonnull dict) {
|
||
showToast(@"转币成功");
|
||
[weakSelf hide];
|
||
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
showToast(msg);
|
||
}];
|
||
return;
|
||
}
|
||
if (self.isHeadline) {
|
||
NSString *content = self.textField.text;
|
||
if (![content isExist]) {
|
||
showToast(@"请填写头条内容");
|
||
return;
|
||
}
|
||
if (content.length > 15) {
|
||
showToast(@"头条内容不能超过15个汉字");
|
||
return;
|
||
}
|
||
MJWeakSelf
|
||
[QXMineNetwork sendHeadlineWithContent:content money:self.coin roomId:self.roomId successBlock:^(NSDictionary * _Nonnull dict) {
|
||
showToast(@"抢头条成功");
|
||
[weakSelf hide];
|
||
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
[weakSelf hide];
|
||
showToast(msg);
|
||
}];
|
||
}else{
|
||
NSString *ratio = self.textField.text;
|
||
if (ratio.doubleValue > 0 && ratio.doubleValue < 100) {
|
||
MJWeakSelf
|
||
[QXMineNetwork roomSetHostRatio:ratio roomId:self.roomId user_id:self.userId successBlock:^(NSDictionary * _Nonnull dict) {
|
||
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(setDirectRatioSuccess)]) {
|
||
[weakSelf.delegate setDirectRatioSuccess];
|
||
[weakSelf hide];
|
||
}
|
||
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
showToast(msg);
|
||
}];
|
||
}else{
|
||
showToast(@"请设置正确的收益比例");
|
||
return;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
-(void)setIsHeadline:(BOOL)isHeadline{
|
||
_isHeadline = isHeadline;
|
||
self.titleLabel.text = @"发头条";
|
||
self.textField.placeholder = @"请输入内容,最多15字";
|
||
self.unitLabel.hidden = YES;
|
||
self.textField.frame = CGRectMake(12, 0, self.scaleBGView.width-24, 44);
|
||
self.messageLabel.frame = CGRectMake(12, self.timeLabel.bottom+12, self.bgView.width-36, self.commitBtn.top-self.timeLabel.bottom-24);
|
||
self.coinBtn.frame = CGRectMake(self.timeLabel.right+10, self.scaleBGView.bottom+12, 200, 18);
|
||
self.coinBtn.hidden = NO;
|
||
self.timeLabel.hidden = NO;
|
||
self.textField.keyboardType = UIKeyboardTypeDefault;
|
||
[self.commitBtn setTitle:@"发布" forState:(UIControlStateNormal)];
|
||
}
|
||
-(void)setMinutes:(NSString *)minutes{
|
||
_minutes = minutes;
|
||
self.timeLabel.text = [NSString stringWithFormat:@"%@分钟",minutes];
|
||
}
|
||
- (void)setCoin:(NSString *)coin{
|
||
_coin = coin;
|
||
[self.coinBtn setTitle:coin forState:(UIControlStateNormal)];
|
||
}
|
||
-(void)setNow_coin:(NSString *)now_coin{
|
||
_now_coin = now_coin;
|
||
if (now_coin.intValue > 0) {
|
||
self.titleLabel.text = @"抢头条";
|
||
self.messageLabel.text = [NSString stringWithFormat:@"当前头条价格%@,抢头条价格%@,可立即覆盖当前头条",now_coin,self.coin];
|
||
}else{
|
||
self.titleLabel.text = @"发头条";
|
||
self.messageLabel.text = @"";
|
||
}
|
||
}
|
||
|
||
-(void)closeAction{
|
||
[self hide];
|
||
}
|
||
|
||
-(void)showInView:(UIView *)view{
|
||
self.textField.text = @"";
|
||
[view addSubview:self];
|
||
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
||
self.bgView.y = (SCREEN_HEIGHT-ScaleWidth(300))/2.0;
|
||
} completion:^(BOOL finished) {
|
||
|
||
}];
|
||
}
|
||
|
||
-(void)hide{
|
||
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
||
self.bgView.y = SCREEN_HEIGHT;
|
||
} completion:^(BOOL finished) {
|
||
[self removeFromSuperview];
|
||
}];
|
||
}
|
||
|
||
@end
|