You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
291 lines
12 KiB
291 lines
12 KiB
4 years ago
|
//
|
||
|
// TFComicDetailHeaderView.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/19.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFComicDetailHeaderView.h"
|
||
|
#import "TFTagboardView.h"
|
||
|
#import "TFCollectionManager.h"
|
||
|
#import "UIView+AZGradient.h"
|
||
|
#import "UIImage+Blur.h"
|
||
|
|
||
|
@interface TFComicDetailHeaderView ()
|
||
|
{
|
||
|
UIView *backFrostedGlassView;
|
||
|
|
||
|
UIView *tagBottomView;
|
||
|
|
||
|
UIImageView *comicCoverImageView;
|
||
|
|
||
|
UILabel *comicTitleLabel;
|
||
|
UIButton *collectButton;
|
||
|
UILabel *hotLabel;
|
||
|
UILabel *authorLabel;
|
||
|
UILabel *collectNumLabel;
|
||
|
|
||
|
TFTagboardView *tagView;
|
||
|
|
||
|
UIVisualEffectView *effectView;
|
||
|
}
|
||
|
@property (nonatomic ,weak) UIImageView *backHoldImageView;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TFComicDetailHeaderView
|
||
|
|
||
|
- (instancetype)init
|
||
|
{
|
||
|
if (self = [super init]) {
|
||
|
|
||
|
[self createSubViews];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)createSubViews
|
||
|
{
|
||
|
UIImageView *backHoldImageView = [[UIImageView alloc] init];
|
||
|
self.backHoldImageView = backHoldImageView;
|
||
|
backHoldImageView.image = HoldImage;
|
||
|
backHoldImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
|
backHoldImageView.clipsToBounds = YES;
|
||
|
[self addSubview:backHoldImageView];
|
||
|
|
||
|
[backHoldImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(0);
|
||
|
make.top.mas_equalTo(0);
|
||
|
make.width.mas_equalTo(SCREEN_WIDTH);
|
||
|
make.height.mas_equalTo(Comic_Detail_HeaderView_Height);
|
||
|
}];
|
||
|
|
||
|
backFrostedGlassView = [[UIView alloc] init];
|
||
|
[self addSubview:backFrostedGlassView];
|
||
|
|
||
|
[backFrostedGlassView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.edges.mas_equalTo(backHoldImageView);
|
||
|
}];
|
||
|
|
||
|
effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
|
||
|
effectView.alpha = 0;
|
||
|
[self addSubview:effectView];
|
||
|
|
||
|
[effectView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.edges.mas_equalTo(backHoldImageView);
|
||
|
}];
|
||
|
|
||
|
tagBottomView = [[UIView alloc] init];
|
||
|
tagBottomView.backgroundColor = kWhiteColor;
|
||
|
tagBottomView.layer.cornerRadius = 20;
|
||
|
[self addSubview:tagBottomView];
|
||
|
|
||
|
[tagBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(0);
|
||
|
make.bottom.mas_equalTo(self.mas_bottom).with.offset(kMargin);
|
||
|
make.width.mas_equalTo(self.mas_width);
|
||
|
make.height.mas_equalTo(80 + kMargin);
|
||
|
}];
|
||
|
|
||
|
comicCoverImageView = [[UIImageView alloc] initWithCornerRadiusAdvance:8 rectCornerType:UIRectCornerAllCorners];
|
||
|
comicCoverImageView.image = HoldImage;
|
||
|
comicCoverImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
|
[comicCoverImageView zy_attachBorderWidth:2 color:kWhiteColor];
|
||
|
[self addSubview:comicCoverImageView];
|
||
|
|
||
|
[comicCoverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.mas_left).with.offset(kMargin);
|
||
|
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- kQuarterMargin);
|
||
|
make.width.mas_equalTo((255) / 2);
|
||
|
make.height.mas_equalTo(kGeometricHeight((255) / 2, 3, 4));
|
||
|
}];
|
||
|
|
||
|
comicTitleLabel = [[UILabel alloc] init];
|
||
|
comicTitleLabel.textColor = kWhiteColor;
|
||
|
comicTitleLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
comicTitleLabel.font = kBoldFont22;
|
||
|
[self addSubview:comicTitleLabel];
|
||
|
|
||
|
[comicTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
|
||
|
make.top.mas_equalTo(comicCoverImageView.mas_top);
|
||
|
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
|
||
|
make.height.mas_equalTo(30);
|
||
|
}];
|
||
|
|
||
|
collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
collectButton.backgroundColor = kMainColor;
|
||
|
collectButton.layer.cornerRadius = 12;
|
||
|
collectButton.hidden = YES;
|
||
|
[collectButton setTitle:TFLocalizedString(@"+收藏") forState:UIControlStateNormal];
|
||
|
[collectButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||
|
[collectButton.titleLabel setFont:kFont12];
|
||
|
[collectButton addTarget:self action:@selector(collectionClick:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
[self addSubview:collectButton];
|
||
|
|
||
|
[collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
|
||
|
make.bottom.mas_equalTo(tagBottomView.mas_top).with.offset(- kHalfMargin);
|
||
|
make.height.mas_equalTo(24);
|
||
|
make.width.mas_equalTo(70.0);
|
||
|
}];
|
||
|
|
||
|
collectNumLabel = [[UILabel alloc] init];
|
||
|
collectNumLabel.backgroundColor = [UIColor clearColor];
|
||
|
collectNumLabel.textColor = kWhiteColor;
|
||
|
collectNumLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
collectNumLabel.font = kMainFont;
|
||
|
[self addSubview:collectNumLabel];
|
||
|
|
||
|
[collectNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
|
||
|
make.bottom.mas_equalTo(collectButton.mas_bottom);
|
||
|
make.right.mas_equalTo(collectButton.mas_left).with.offset(-kQuarterMargin);
|
||
|
make.height.mas_equalTo(20);
|
||
|
}];
|
||
|
|
||
|
hotLabel = [[UILabel alloc] init];
|
||
|
hotLabel.backgroundColor = [UIColor clearColor];
|
||
|
hotLabel.textColor = kWhiteColor;
|
||
|
hotLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
hotLabel.font = kMainFont;
|
||
|
[self addSubview:hotLabel];
|
||
|
|
||
|
[hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
|
||
|
make.bottom.mas_equalTo(collectNumLabel.mas_top).with.offset(- kQuarterMargin);
|
||
|
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
|
||
|
make.height.mas_equalTo(collectNumLabel.mas_height);
|
||
|
}];
|
||
|
|
||
|
authorLabel = [[UILabel alloc] init];
|
||
|
authorLabel.backgroundColor = [UIColor clearColor];
|
||
|
authorLabel.textColor = kWhiteColor;
|
||
|
authorLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
authorLabel.font = kMainFont;
|
||
|
[self addSubview:authorLabel];
|
||
|
|
||
|
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
|
||
|
make.bottom.mas_equalTo(hotLabel.mas_top).with.offset(- kQuarterMargin);
|
||
|
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
|
||
|
make.height.mas_equalTo(collectNumLabel.mas_height);
|
||
|
}];
|
||
|
|
||
|
tagView = [[TFTagboardView alloc] init];
|
||
|
tagView.textAlignment = TFTagboardTextAlignmentLeft;
|
||
|
tagView.borderStyle = TFTagboardBorderStyleFill;
|
||
|
tagView.layoutStyle = TFTagboardLayoutStyleScroll;
|
||
|
tagView.spacing = 15;
|
||
|
tagView.cornerRadius = 8.5;
|
||
|
[self addSubview:tagView];
|
||
|
|
||
|
[tagView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
|
||
|
make.top.mas_equalTo(tagBottomView.mas_top).with.offset(kHalfMargin);
|
||
|
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
|
||
|
make.height.mas_equalTo(20);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)setComicProductionModel:(TFProductionModel *)comicProductionModel
|
||
|
{
|
||
|
if (_comicProductionModel != comicProductionModel) {
|
||
|
_comicProductionModel = comicProductionModel;
|
||
|
|
||
|
collectButton.hidden = NO;
|
||
|
|
||
|
WS(weakSelf)
|
||
|
[[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:comicProductionModel.horizontal_cover.length > 0 ?comicProductionModel.horizontal_cover:comicProductionModel.vertical_cover] options:YYWebImageOptionSetImageWithFadeAnimation progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
|
||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||
|
SS(strongSelf)
|
||
|
weakSelf.backHoldImageView.image = [image imgWithLightAlpha:0.4 radius:3 colorSaturationFactor:1.8];
|
||
|
strongSelf->backFrostedGlassView.backgroundColor = kColorRGBA(0, 0, 0, 0.4);
|
||
|
});
|
||
|
}];
|
||
|
|
||
|
|
||
|
[comicCoverImageView setImageWithURL:[NSURL URLWithString:comicProductionModel.vertical_cover] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
|
||
|
|
||
|
comicTitleLabel.attributedText = [self formatAttributedText:comicProductionModel.name];
|
||
|
|
||
|
hotLabel.attributedText = [self formatAttributedText:comicProductionModel.hot_num];
|
||
|
|
||
|
collectNumLabel.attributedText = [self formatAttributedText:comicProductionModel.total_favors];
|
||
|
|
||
|
authorLabel.attributedText = [self formatAttributedText:comicProductionModel.author];
|
||
|
|
||
|
tagView.tagboardArray = comicProductionModel.tag;
|
||
|
|
||
|
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProductionModel:comicProductionModel]) {
|
||
|
collectButton.tag = 1;
|
||
|
collectButton.backgroundColor = [kMainColor colorWithAlphaComponent:0.75];
|
||
|
[collectButton setTitle:TFLocalizedString(@"已收藏") forState:UIControlStateNormal];
|
||
|
} else {
|
||
|
collectButton.tag = 0;
|
||
|
collectButton.backgroundColor = kMainColor;
|
||
|
[collectButton setTitle:TFLocalizedString(@"+收藏") forState:UIControlStateNormal];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (NSAttributedString *)formatAttributedText:(NSString *)normalText
|
||
|
{
|
||
|
// NSShadow *shadow = [[NSShadow alloc] init];
|
||
|
// shadow.shadowBlurRadius = 6.0;
|
||
|
// shadow.shadowOffset = CGSizeMake(0, 0);
|
||
|
// shadow.shadowColor = [UIColor blackColor];
|
||
|
|
||
|
NSMutableAttributedString *authorAttString = [[NSMutableAttributedString alloc] initWithString:normalText?:@""];
|
||
|
// [authorAttString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, authorAttString.length)];
|
||
|
return authorAttString;
|
||
|
}
|
||
|
|
||
|
- (void)setHeaderViewAlpha:(CGFloat)headerViewAlpha
|
||
|
{
|
||
|
_headerViewAlpha = headerViewAlpha;
|
||
|
|
||
|
[tagBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.height.mas_equalTo(80 * headerViewAlpha);
|
||
|
}];
|
||
|
|
||
|
comicCoverImageView.alpha = headerViewAlpha;
|
||
|
comicTitleLabel.alpha = headerViewAlpha;
|
||
|
collectButton.alpha = headerViewAlpha;
|
||
|
hotLabel.alpha = headerViewAlpha;
|
||
|
collectNumLabel.alpha = headerViewAlpha;
|
||
|
authorLabel.alpha = headerViewAlpha;
|
||
|
tagView.alpha = headerViewAlpha;
|
||
|
backFrostedGlassView.alpha = headerViewAlpha;
|
||
|
|
||
|
effectView.alpha = 1 - headerViewAlpha;
|
||
|
}
|
||
|
|
||
|
- (void)reloadHeaderView
|
||
|
{
|
||
|
if (![[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProductionModel:self.comicProductionModel]) {
|
||
|
collectButton.backgroundColor = kMainColor;
|
||
|
[collectButton setTitle:TFLocalizedString(@"+收藏") forState:UIControlStateNormal];
|
||
|
} else {
|
||
|
collectButton.backgroundColor = [kMainColor colorWithAlphaComponent:0.75];
|
||
|
[collectButton setTitle:TFLocalizedString(@"已收藏") forState:UIControlStateNormal];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)collectionClick:(UIButton *)sender
|
||
|
{
|
||
|
if (![[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProductionModel:self.comicProductionModel]) {
|
||
|
|
||
|
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.comicProductionModel.production_id productionType:TFProductionTypeComic complete:nil];
|
||
|
|
||
|
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] addCollectionWithProductionModel:self.comicProductionModel]) {
|
||
|
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
|
||
|
}
|
||
|
|
||
|
[self reloadHeaderView];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|