// // HDLEZVideoQualityBoxView.m // EZSDK // // Created by Davin on 2023/6/25. // #import "HDLEZVideoQualityBoxView.h" #define radiusValue 8. #define arrowWidth 8. @interface HDLEZVideoQualityBoxView () @property (nonatomic, strong) UIButton *smoothBtn; @property (nonatomic, strong) UIButton *balanceBtn; @property (nonatomic, strong) UIButton *hdFullBtn; @property (nonatomic, copy) void(^qualityOperation)(HDLEZVideoFullSceneOperation operationType); @end @implementation HDLEZVideoQualityBoxView - (instancetype)initWithFrame:(CGRect)frame{ if(self = [super initWithFrame:frame]){ [self createSubviews]; } return self; } - (void)createSubviews { self.backgroundColor = [UIColor clearColor]; [self addSubview:self.smoothBtn]; [self addSubview:self.balanceBtn]; [self addSubview:self.hdFullBtn]; [self.smoothBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.mas_top); make.left.mas_equalTo(self.mas_left); make.right.mas_equalTo(self.mas_right); }]; [self.balanceBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.smoothBtn.mas_bottom); make.left.mas_equalTo(self.mas_left); make.right.mas_equalTo(self.mas_right); make.height.mas_equalTo(self.smoothBtn.mas_height); }]; [self.hdFullBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.balanceBtn.mas_bottom); make.left.mas_equalTo(self.mas_left); make.bottom.mas_equalTo(self.mas_bottom).offset(-arrowWidth); make.right.mas_equalTo(self.mas_right); make.height.mas_equalTo(self.smoothBtn.mas_height); }]; [self.smoothBtn addTarget:self action:@selector(selectedSmooth) forControlEvents:UIControlEventTouchUpInside]; [self.balanceBtn addTarget:self action:@selector(selectedBalance) forControlEvents:UIControlEventTouchUpInside]; [self.hdFullBtn addTarget:self action:@selector(selectedHdFull) forControlEvents:UIControlEventTouchUpInside]; } - (void)drawRect:(CGRect)rect{ CGFloat w = rect.size.width; CGFloat h = rect.size.height; UIBezierPath *path = [UIBezierPath bezierPath]; UIColor *bgColor; [path moveToPoint:CGPointMake(0, h - radiusValue - arrowWidth)]; [path addArcWithCenter:CGPointMake(radiusValue, h - radiusValue - arrowWidth) radius:radiusValue startAngle:M_PI endAngle:M_PI_2 clockwise:NO]; [path addLineToPoint:CGPointMake(w/2. - arrowWidth, h - arrowWidth)]; [path addLineToPoint:CGPointMake(w/2., h)]; [path addLineToPoint:CGPointMake(w/2. + arrowWidth, h - arrowWidth)]; [path addLineToPoint:CGPointMake(w - radiusValue, h - arrowWidth)]; [path addArcWithCenter:CGPointMake(w - radiusValue, h - radiusValue - arrowWidth) radius:radiusValue startAngle:M_PI_2 endAngle:0 clockwise:NO]; [path addLineToPoint:CGPointMake(w, radiusValue)]; [path addArcWithCenter:CGPointMake(w - radiusValue, radiusValue) radius:radiusValue startAngle:0 endAngle:-M_PI_2 clockwise:NO]; [path addLineToPoint:CGPointMake(radiusValue, 0)]; [path addArcWithCenter:CGPointMake(radiusValue, radiusValue) radius:radiusValue startAngle:-M_PI_2 endAngle:-M_PI clockwise:NO]; [path addLineToPoint:CGPointMake(0, h - radiusValue - arrowWidth)]; bgColor = HDLEZHEXCOLOR(0x292929, 1.); [bgColor setFill]; [path fill]; [path setLineWidth:0.5]; [HDLEZHEXCOLOR(0x292929, 1.) setStroke]; [path stroke]; [path closePath]; } #pragma mark - PublishMethod - (void)videoQualityChange:(void(^)(HDLEZVideoFullSceneOperation operationType))qualityBlock { self.qualityOperation = qualityBlock; } #pragma mark - PrivateMethod - (void)selectedSmooth { if (self.qualityOperation) { self.qualityOperation(HDLEZVideoFullSceneOperationOfSmooth); } } - (void)selectedBalance { if (self.qualityOperation) { self.qualityOperation(HDLEZVideoFullSceneOperationOfBalance); } } - (void)selectedHdFull { if (self.qualityOperation) { self.qualityOperation(HDLEZVideoFullSceneOperationOfHDFull); } } #pragma mark - Getter - (UIButton *)smoothBtn { if (!_smoothBtn) { _smoothBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_smoothBtn setImage:[UIImage imageNamed:@"hdl_ez_cat_eyes_full_smooth"] forState:UIControlStateNormal]; } return _smoothBtn; } - (UIButton *)balanceBtn { if (!_balanceBtn) { _balanceBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_balanceBtn setImage:[UIImage imageNamed:@"hdl_ez_cat_eyes_full_balance"] forState:UIControlStateNormal]; } return _balanceBtn; } - (UIButton *)hdFullBtn { if (!_hdFullBtn) { _hdFullBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_hdFullBtn setImage:[UIImage imageNamed:@"hdl_ez_cat_eyes_full_hd_full"] forState:UIControlStateNormal]; } return _hdFullBtn; } @end