Files
featherVoice/QXLive/活动/QXDrawGiftCenterView.m

229 lines
6.9 KiB
Mathematica
Raw Normal View History

2025-10-20 09:43:10 +08:00
//
// QXDrawGiftCenterView.m
// QXLive
//
// Created by on 2025/8/27.
//
#import "QXDrawGiftCenterView.h"
static CGFloat lineWidth = 13;
@implementation QXDrawGiftCenterProgressView
- (instancetype)init
{
self = [super init];
if (self) {
self.progressColor = RGB16(0x32F6CB);
self.backgroundColor = RGB16(0x70ADFA);
self.cycleLabel = [[UILabel alloc] init];
self.cycleLabel.font = [UIFont boldSystemFontOfSize:16];
self.cycleLabel.textColor = RGB16(0xffffff);
[self addSubview:self.cycleLabel];
[self.cycleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.centerY.equalTo(self);
}];
[self bringSubviewToFront:self.cycleLabel];
}
return self;
}
-(void)drawRect:(CGRect)rect{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
//
CGPoint center = CGPointMake(rect.size.width / 2, rect.size.height / 2);
CGFloat radius = MIN(ScaleWidth(70), ScaleWidth(70)) / 2 - lineWidth / 2;
//
[self drawProgressWithCenter:center radius:radius];
CGContextRestoreGState(context);
}
- (void)setProgress:(double)progress {
_progress = MAX(0.0, MIN(1.0, progress)); // 0-1
[self setNeedsDisplay];
self.cycleLabel.text = [NSString stringWithFormat:@"%d%%",(int)(progress*100)];
[self bringSubviewToFront:self.cycleLabel];
}
- (void)drawProgressWithCenter:(CGPoint)center radius:(CGFloat)radius {
if (self.progress > 0) {
//
CGFloat endAngle = -M_PI_2 + 2 * M_PI * self.progress;
UIBezierPath *progressPath = [UIBezierPath bezierPathWithArcCenter:center
radius:radius
startAngle:-M_PI_2 // -90
endAngle:endAngle
clockwise:YES];
[self.progressColor setStroke];
progressPath.lineWidth = lineWidth;
progressPath.lineCapStyle = kCGLineCapRound;
[progressPath stroke];
}
}
@end
@implementation QXDrawGiftCenterView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)setModel:(QXGiftActivityModel *)model{
_model = model;
if (model.is_xlh.intValue == 1) {
self.hidden = NO;
}else{
self.hidden = YES;
}
double progress = (model.xlh_data.current_num.doubleValue/model.xlh_data.start_num.doubleValue);
[self setProgress:progress];
QXDrawGiftCenterType type = model.xlh_data.status.integerValue;
[self setType:type];
}
-(void)initSubviews{
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sky_status_bg"]];
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
[self addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self);
make.height.equalTo(self.bgImageView.mas_width);
}];
self.cycleBgView = [[UIView alloc] init];
self.cycleBgView.backgroundColor = RGB16(0x70ADFA);
[self.cycleBgView addRoundedCornersWithRadius:ScaleWidth(35)];
[self addSubview:self.cycleBgView];
[self.cycleBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(ScaleWidth(70));
make.centerX.equalTo(self.bgImageView);
make.centerY.equalTo(self.bgImageView).offset(10);
}];
self.startBtn = [[UIButton alloc] init];
[self.startBtn addTarget:self action:@selector(startAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.startBtn];
[self.startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(ScaleWidth(92));
make.height.mas_equalTo(ScaleWidth(54));
make.centerX.equalTo(self);
make.bottom.equalTo(self);
}];
self.progressView = [[QXDrawGiftCenterProgressView alloc] init];
[self.progressView addRoundedCornersWithRadius:ScaleWidth(35)];
[self addSubview:self.progressView];
[self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(ScaleWidth(70));
make.centerX.centerY.equalTo(self.cycleBgView);
// make.centerY.equalTo(self.bgImageView).offset(10);
}];
// [self startHide];
}
-(void)startAction{
switch (self.type) {
case QXDrawGiftCenterTypeWait:{
showToast(@"活动未开始");
}
break;
case QXDrawGiftCenterTypeWill:{
showToast(@"活动即将开始");
}
break;
case QXDrawGiftCenterTypeStart:{
if (self.startBlock) {
self.startBlock();
}
}
break;
default:
break;
}
}
-(void)startHide{
[UIView animateWithDuration:1 animations:^{
// self.bgImageView.alpha = 0;
self.alpha = 0;
} completion:^(BOOL finished) {
[self startShow];
}];
}
-(void)startShow{
[UIView animateWithDuration:1 animations:^{
// self.bgImageView.alpha = 1;
self.alpha = 1;
} completion:^(BOOL finished) {
[self startHide];
}];
}
- (void)setProgress:(CGFloat)progress {
_progress = progress;
self.progressView.progress = progress;
}
-(void)setActivityType:(QXActivityType)activityType{
_activityType = activityType;
switch (_activityType) {
case QXActivityTypeSky:{
self.bgImageView.image = [UIImage imageNamed:@"sky_status_bg"];
}
break;
case QXActivityTypeAge:{
self.bgImageView.image = [UIImage imageNamed:@"age_status_bg"];
}
break;
case QXActivityTypeTime:{
self.bgImageView.image = [UIImage imageNamed:@"time_status_bg"];
}
break;
default:
break;
}
}
-(void)setType:(QXDrawGiftCenterType)type{
_type = type;
switch (_type) {
case QXDrawGiftCenterTypeWait:{
[self.startBtn setBackgroundImage:[UIImage imageNamed:@"meet_status_wait"] forState:(UIControlStateNormal)];
}
break;
case QXDrawGiftCenterTypeWill:{
[self.startBtn setBackgroundImage:[UIImage imageNamed:@"meet_status_will"] forState:(UIControlStateNormal)];
}
break;
case QXDrawGiftCenterTypeStart:{
[self.startBtn setBackgroundImage:[UIImage imageNamed:@"meet_status_start"] forState:(UIControlStateNormal)];
[self setProgress:1];
}
break;
default:
break;
}
}
@end