feat: 完成 代充页面修改 | 开屏 & 首页banner 支持 svga
This commit is contained in:
@@ -9,6 +9,114 @@
|
||||
#import <SDCycleScrollView/SDCycleScrollView.h>
|
||||
#import "XPNewHomeItemCell.h"
|
||||
#import "PIPageControl.h"
|
||||
#import <SVGA.h>
|
||||
|
||||
@interface HomeBannerCell : UICollectionViewCell
|
||||
|
||||
@property(nonatomic, assign) HomeBannerInfoSkipType type;
|
||||
@property(nonatomic, strong) HomeBannerFillVoInfoModel *cellFillVoMode;
|
||||
@property(nonatomic, strong) NSString *imageURLString;
|
||||
@property(nonatomic, strong) NetImageView *imageView;
|
||||
@property(nonatomic, strong) SVGAImageView *svgaImageView;
|
||||
@property(nonatomic, strong) SVGAVideoEntity *videoItem;
|
||||
|
||||
@end
|
||||
|
||||
@implementation HomeBannerCell
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
_imageView = [[NetImageView alloc] init];
|
||||
[self.contentView addSubview:self.imageView];
|
||||
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.contentView);
|
||||
}];
|
||||
|
||||
_svgaImageView = [[SVGAImageView alloc] init];
|
||||
self.svgaImageView.loops = -1;
|
||||
self.svgaImageView.autoPlay = YES;
|
||||
self.svgaImageView.clearsAfterStop = NO;
|
||||
[self.contentView addSubview:self.svgaImageView];
|
||||
[self.svgaImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.contentView);
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)prepareForReuse {
|
||||
[super prepareForReuse];
|
||||
}
|
||||
|
||||
- (void)setImageURLString:(NSString *)imageURLString {
|
||||
|
||||
if (self.type == HomeBannerInfoSkipType_Web_CP ||
|
||||
self.type == HomeBannerInfoSkipType_Web_Custom ||
|
||||
self.type == HomeBannerInfoSkipType_Web_WeekStar) {
|
||||
self.imageView.hidden = YES;
|
||||
if (self.videoItem) {
|
||||
[self playSVGAWith:self.videoItem];
|
||||
} else {
|
||||
SVGAParser *p = [[SVGAParser alloc] init];
|
||||
@kWeakify(self);
|
||||
[p parseWithURL:[NSURL URLWithString:imageURLString] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
||||
@kStrongify(self);
|
||||
if (videoItem) {
|
||||
self.videoItem = videoItem;
|
||||
[self playSVGAWith:videoItem];
|
||||
}
|
||||
} failureBlock:^(NSError * _Nullable error) {
|
||||
@kStrongify(self);
|
||||
self.imageView.hidden = NO;
|
||||
self.imageView.imageUrl = imageURLString;
|
||||
}];
|
||||
}
|
||||
} else {
|
||||
self.imageView.hidden = NO;
|
||||
self.imageView.imageUrl = imageURLString;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)playSVGAWith:(SVGAVideoEntity *)videoItem {
|
||||
self.svgaImageView.videoItem = videoItem;
|
||||
if (self.cellFillVoMode) {
|
||||
[self updateSvgaImage:self.cellFillVoMode.avatar key:@"avatar"];
|
||||
[self updateSvgaImage:self.cellFillVoMode.picUrl key:@"gift"];
|
||||
[self updateSvgaImage:self.cellFillVoMode.avatar key:@"avatar_1"];
|
||||
[self updateSvgaImage:self.cellFillVoMode.loverAvatar key:@"avatar_2"];
|
||||
|
||||
[self updateSvgaText:[NSString stringWithFormat:@"ID: %@", self.cellFillVoMode.erbanNo] key:@"id"];
|
||||
[self updateSvgaText:self.cellFillVoMode.giftName key:@"name"];
|
||||
[self updateSvgaText:[NSString stringWithFormat:@"ID: %@", self.cellFillVoMode.erbanNo] key:@"id_1"];
|
||||
[self updateSvgaText:[NSString stringWithFormat:@"ID: %@", self.cellFillVoMode.loverErbanNo] key:@"id_2"];
|
||||
}
|
||||
|
||||
[self.svgaImageView startAnimation];
|
||||
}
|
||||
|
||||
- (void)updateSvgaImage:(NSString *)imagePath key:(NSString *)key {
|
||||
if (self.svgaImageView && ![NSString isEmpty:imagePath] && ![NSString isEmpty:key]) {
|
||||
[self.svgaImageView setImageWithURL:[NSURL URLWithString:imagePath] forKey:key];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateSvgaText:(NSString *)content key:(NSString *)key {
|
||||
if (self.svgaImageView && ![NSString isEmpty:content] && ![NSString isEmpty:key]) {
|
||||
NSAttributedString *string = [[NSAttributedString alloc] initWithString:content
|
||||
attributes:@{
|
||||
NSFontAttributeName: kFontMedium(30),
|
||||
NSForegroundColorAttributeName: UIColorFromRGB(0xF9F8CF)
|
||||
}];
|
||||
[self.svgaImageView setAttributedText:string
|
||||
forKey:key];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface XPNewHomeHeadView ()<SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
||||
@property(nonatomic,strong) UICollectionView *collectionView;
|
||||
///轮播图
|
||||
@@ -44,6 +152,19 @@
|
||||
}];
|
||||
}
|
||||
#pragma mark - SDCycleScrollViewDelegate
|
||||
|
||||
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view {
|
||||
return [HomeBannerCell class];
|
||||
}
|
||||
|
||||
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view {
|
||||
HomeBannerCell *bannerCell = (HomeBannerCell *)cell;
|
||||
HomeBannerInfoModel * bannerInfo = [self.bannerList xpSafeObjectAtIndex:index];
|
||||
bannerCell.type = bannerInfo.skipType;
|
||||
bannerCell.cellFillVoMode = bannerInfo.fillVo;
|
||||
bannerCell.imageURLString = bannerInfo.bannerPic;
|
||||
}
|
||||
|
||||
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
|
||||
HomeBannerInfoModel * bannerInfo = [self.bannerList xpSafeObjectAtIndex:index];
|
||||
if(bannerInfo != nil && self.delegate && [self.delegate respondsToSelector:@selector(selectBannerListWithModel:)]){
|
||||
|
||||
Reference in New Issue
Block a user