Commit 2c30dc06 cgx

黑夜模式针对不好处理的UIImageView添加遮罩

1 个父辈 438fbb29
...@@ -7,6 +7,13 @@ ...@@ -7,6 +7,13 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
// 蒙版类型
typedef NS_ENUM(NSInteger, MaskType) {
MaskTypeNormal, // 正常,不带圆角
MaskTypeAllCorner, // 四周带圆角
MaskTypeCornerBottom, // 底部带圆角
};
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface UIView (Extras) @interface UIView (Extras)
...@@ -25,8 +32,14 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -25,8 +32,14 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
- (UIViewController *)ds_viewController; - (UIViewController *)ds_viewController;
/// 用于调试UI
- (void)debugViewShowBorder; - (void)debugViewShowBorder;
/// 设置圆角
/// @param radius radius
- (void)cornerRadius:(CGFloat)radius; - (void)cornerRadius:(CGFloat)radius;
// 添加遮罩
- (void)addMaskWithType:(MaskType)type cornerRadius:(CGFloat)cornerRadius;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -109,4 +109,21 @@ ...@@ -109,4 +109,21 @@
self.layer.masksToBounds = YES; self.layer.masksToBounds = YES;
} }
- (void)addMaskWithType:(MaskType)type cornerRadius:(CGFloat)cornerRadius {
UIView *maskView = [[UIView alloc] initWithFrame:self.bounds];
maskView.backgroundColor = DSBlack;
maskView.alpha = .3;
[self addSubview:maskView];
UIRectCorner rectCorner = UIRectCornerAllCorners;
if (type == MaskTypeCornerBottom) {
rectCorner = UIRectCornerBottomLeft | UIRectCornerBottomRight;
}
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:maskView.bounds byRoundingCorners:rectCorner cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = maskView.bounds;
maskLayer.path = path.CGPath;
maskView.layer.mask = maskLayer;
}
@end @end
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
@interface AudioDetailHeaderView () @interface AudioDetailHeaderView ()
@property (nonatomic, strong) UIImageView *bgIV; @property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UIView *maskView;
@property (nonatomic, strong) UIImageView *audioIV; @property (nonatomic, strong) UIImageView *audioIV;
@property (nonatomic, strong) UILabel *audioNameLab; @property (nonatomic, strong) UILabel *audioNameLab;
@property (nonatomic, strong) UILabel *audioDescLab; @property (nonatomic, strong) UILabel *audioDescLab;
...@@ -24,21 +23,14 @@ ...@@ -24,21 +23,14 @@
self.clipsToBounds = YES; self.clipsToBounds = YES;
[self addSubview:self.bgIV]; [self addSubview:self.bgIV];
[self addSubview:self.audioIV];
[self addSubview:self.audioNameLab]; [self addSubview:self.audioNameLab];
if (courseType == CourseTypeSafe) { if (courseType == CourseTypeSafe) {
[self addSubview:self.audioIV];
[self addSubview:self.audioDescLab]; [self addSubview:self.audioDescLab];
[self addSubview:self.cornerView]; [self addSubview:self.cornerView];
self.audioDescLab.text = model.audio_desc; self.audioDescLab.text = model.audio_desc;
} else {
[self addSubview:self.maskView];
[self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.width.height.equalTo(@118);
make.top.equalTo(self).offset(118);
}];
} }
[self.bgIV yy_setImageWithURL:[NSURL URLWithString:model.bg_url] placeholder:[UIImage imageNamed:@"bannerPlaceholder"]]; [self.bgIV yy_setImageWithURL:[NSURL URLWithString:model.bg_url] placeholder:[UIImage imageNamed:@"bannerPlaceholder"]];
...@@ -60,9 +52,9 @@ ...@@ -60,9 +52,9 @@
make.top.equalTo(self).offset(105); make.top.equalTo(self).offset(105);
make.width.height.equalTo(@100); make.width.height.equalTo(@100);
} else { } else {
[self.audioIV mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self);
make.edges.equalTo(self.maskView); make.width.height.equalTo(@118);
}]; make.top.equalTo(self).offset(118);
} }
}]; }];
[self.audioNameLab mas_makeConstraints:^(MASConstraintMaker *make) { [self.audioNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
...@@ -86,6 +78,18 @@ ...@@ -86,6 +78,18 @@
make.height.equalTo(@40); make.height.equalTo(@40);
}]; }];
} }
// 更新布局
[self layoutIfNeeded];
if (courseType == CourseTypeRelax) {
// 添加遮罩
if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
[self.bgIV addMaskWithType:MaskTypeCornerBottom cornerRadius:22.0];
[self.audioIV addMaskWithType:MaskTypeAllCorner cornerRadius:12.0];
}
} else {
self.bgIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .3, .5);
self.audioIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .3, .5);
}
} }
return self; return self;
} }
...@@ -94,25 +98,13 @@ ...@@ -94,25 +98,13 @@
- (UIImageView *)bgIV { - (UIImageView *)bgIV {
if (!_bgIV) { if (!_bgIV) {
_bgIV = [UIImageView new]; _bgIV = [UIImageView new];
_bgIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, .5);
} }
return _bgIV; return _bgIV;
} }
- (UIView *)maskView {
if (!_maskView) {
_maskView = [UIView new];
_maskView.backgroundColor = DSWhite;
[_maskView cornerRadius:15.0];
[_maskView addSubview:self.audioIV];
}
return _maskView;
}
- (UIImageView *)audioIV { - (UIImageView *)audioIV {
if (!_audioIV) { if (!_audioIV) {
_audioIV = [UIImageView new]; _audioIV = [UIImageView new];
_audioIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .8, .5);
} }
return _audioIV; return _audioIV;
} }
...@@ -128,7 +120,7 @@ ...@@ -128,7 +120,7 @@
- (UILabel *)audioDescLab { - (UILabel *)audioDescLab {
if (!_audioDescLab) { if (!_audioDescLab) {
_audioDescLab = [UILabel labWithFont:SysFont(14.0)]; _audioDescLab = [UILabel labWithFont:SysFont(14.0)];
_audioDescLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHex(0xCAC9CD), DSWhite); _audioDescLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
} }
return _audioDescLab; return _audioDescLab;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!