213 lines
6.4 KiB
Objective-C
213 lines
6.4 KiB
Objective-C
//
|
||
// XPMineHeaderView.m
|
||
// xplan-ios
|
||
//
|
||
// Created by 冯硕 on 2021/9/22.
|
||
//
|
||
|
||
#import "XPMineUserInfoHeaderView.h"
|
||
///Third
|
||
#import <Masonry/Masonry.h>
|
||
#import <SDCycleScrollView/SDCycleScrollView.h>
|
||
#import "SDPhotoBrowser.h"
|
||
#import <ReactiveObjC/ReactiveObjC.h>
|
||
///Tool
|
||
#import "ThemeColor.h"
|
||
#import "XPMacro.h"
|
||
#import "UIImageView+LoadImage.h"
|
||
#import "UIImageView+Vague.h"
|
||
///Model
|
||
#import "UserInfoModel.h"
|
||
|
||
@interface XPMineUserInfoImageCollectionViewCell : UICollectionViewCell
|
||
///
|
||
@property (nonatomic,strong) UIImageView *logoImageView;
|
||
@end
|
||
|
||
@implementation XPMineUserInfoImageCollectionViewCell
|
||
|
||
- (instancetype)initWithFrame:(CGRect)frame
|
||
{
|
||
self = [super initWithFrame:frame];
|
||
if (self) {
|
||
[self initSubViews];
|
||
[self initSubViewConstraints];
|
||
}
|
||
return self;
|
||
}
|
||
|
||
#pragma mark - Private Method
|
||
- (void)initSubViews {
|
||
[self.contentView addSubview:self.logoImageView];
|
||
}
|
||
|
||
- (void)initSubViewConstraints {
|
||
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self.contentView);
|
||
}];
|
||
}
|
||
|
||
#pragma mark - Getters And Setters
|
||
- (UIImageView *)logoImageView {
|
||
if (!_logoImageView) {
|
||
_logoImageView = [[UIImageView alloc] init];
|
||
_logoImageView.userInteractionEnabled = YES;
|
||
_logoImageView.layer.masksToBounds = YES;
|
||
_logoImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
}
|
||
return _logoImageView;
|
||
}
|
||
|
||
@end
|
||
|
||
|
||
@interface XPMineUserInfoHeaderView ()<SDCycleScrollViewDelegate, SDPhotoBrowserDelegate>
|
||
///覆盖的
|
||
@property (nonatomic,strong) UIView * coverView;
|
||
///轮播图
|
||
@property (nonatomic,strong) SDCycleScrollView *cycleScrollView;
|
||
///显示当前的页数
|
||
@property (nonatomic,strong) UILabel *pageLabel;
|
||
///图片数组
|
||
@property (nonatomic,strong) NSArray *imageUrls;
|
||
@end
|
||
|
||
@implementation XPMineUserInfoHeaderView
|
||
|
||
- (instancetype)initWithFrame:(CGRect)frame {
|
||
self = [super initWithFrame:frame];
|
||
if (self) {
|
||
[self initSubViews];
|
||
[self initSubViewConstraints];
|
||
}
|
||
return self;
|
||
}
|
||
#pragma mark - Private Method
|
||
- (void)initSubViews {
|
||
[self addSubview:self.cycleScrollView];
|
||
[self addSubview:self.coverView];
|
||
[self addSubview:self.pageLabel];
|
||
}
|
||
|
||
- (void)initSubViewConstraints {
|
||
[self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self);
|
||
}];
|
||
|
||
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self.cycleScrollView);
|
||
}];
|
||
|
||
[self.pageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.right.mas_equalTo(-15);
|
||
make.width.mas_equalTo(35);
|
||
make.height.mas_equalTo(16);
|
||
make.top.mas_equalTo(self).offset(148 + kSafeAreaTopHeight);
|
||
}];
|
||
}
|
||
#pragma mark - SDPhotoBrowserDelegate
|
||
- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
|
||
NSString * photoUrl = [self.imageUrls objectAtIndex:index];
|
||
return [NSURL URLWithString:photoUrl];
|
||
}
|
||
|
||
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
|
||
return [UIImageConstant defalutBannerPlaceholder];
|
||
}
|
||
|
||
#pragma mark - SDCycleScrollViewDelegate
|
||
/** 如果你需要自定义cell样式,请在实现此代理方法返回你的自定义cell的class。 */
|
||
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view {
|
||
return [XPMineUserInfoImageCollectionViewCell class];
|
||
}
|
||
|
||
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view {
|
||
XPMineUserInfoImageCollectionViewCell * imageCell = (XPMineUserInfoImageCollectionViewCell *)cell;
|
||
NSString *url = [self.imageUrls objectAtIndex:index];
|
||
@weakify(imageCell);
|
||
[imageCell.logoImageView load_imageWithUrl:url placeholderImage:[UIImageConstant defalutBannerPlaceholder] type:ImageTypeUserInfoAlbum success:^(UIImage * _Nonnull image) {
|
||
@strongify(imageCell);
|
||
if (image) {
|
||
[imageCell.logoImageView setImageToBlur:image blurRadius:45];
|
||
}
|
||
}];
|
||
}
|
||
|
||
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
|
||
self.pageLabel.text = [NSString stringWithFormat:@"%d/%lu",(index + 1), (unsigned long)self.imageUrls.count];
|
||
}
|
||
|
||
// 轮播图点击
|
||
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
|
||
NSInteger count = self.imageUrls.count;
|
||
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init];
|
||
browser.sourceImagesContainerView = self.cycleScrollView;
|
||
browser.delegate = self;
|
||
browser.imageCount = count;
|
||
browser.currentImageIndex = index;
|
||
browser.isMe = NO;
|
||
[browser show];
|
||
}
|
||
#pragma mark - Getters And Setters
|
||
- (void)setUserInfo:(UserInfoModel *)userInfo {
|
||
_userInfo = userInfo;
|
||
// 轮播图
|
||
NSMutableArray * imageUrls;
|
||
if (self.userInfo.privatePhoto.count > 0) {
|
||
imageUrls = [[[self.userInfo.privatePhoto.rac_sequence map:^id _Nullable(UserPhoto * _Nullable value) {
|
||
return value.photoUrl;
|
||
}] array] mutableCopy] ;
|
||
}
|
||
if (self.userInfo.avatar.length > 0) {
|
||
if (imageUrls.count >0) {
|
||
[imageUrls addObject:self.userInfo.avatar];
|
||
} else {
|
||
imageUrls = [NSMutableArray array];
|
||
[imageUrls addObject:self.userInfo.avatar];
|
||
}
|
||
|
||
}
|
||
if (imageUrls.count > 0) {
|
||
self.imageUrls = imageUrls;
|
||
self.cycleScrollView.imageURLStringsGroup = imageUrls;
|
||
self.pageLabel.text = [NSString stringWithFormat:@"1/%lu",(unsigned long)imageUrls.count];
|
||
}
|
||
}
|
||
- (UIView *)coverView {
|
||
if (!_coverView) {
|
||
_coverView = [[UIView alloc] init];
|
||
_coverView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
|
||
_coverView.alpha = 0.2;
|
||
}
|
||
return _coverView;
|
||
}
|
||
|
||
- (SDCycleScrollView *)cycleScrollView {
|
||
if (!_cycleScrollView) {
|
||
_cycleScrollView = [[SDCycleScrollView alloc] init];
|
||
_cycleScrollView.backgroundColor = [UIColor clearColor];
|
||
_cycleScrollView.delegate = self;
|
||
_cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
|
||
_cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;;
|
||
_cycleScrollView.placeholderImage = [UIImageConstant defaultAvatarPlaceholder];
|
||
_cycleScrollView.autoScroll = NO;
|
||
}
|
||
return _cycleScrollView;
|
||
}
|
||
|
||
- (UILabel *)pageLabel {
|
||
if (!_pageLabel) {
|
||
_pageLabel = [[UILabel alloc] init];
|
||
_pageLabel.font = [UIFont systemFontOfSize:10];
|
||
_pageLabel.textColor = [ThemeColor textThirdColor];
|
||
_pageLabel.textAlignment = NSTextAlignmentCenter;
|
||
_pageLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
|
||
_pageLabel.alpha = 0.1;
|
||
_pageLabel.layer.masksToBounds = YES;
|
||
_pageLabel.layer.cornerRadius = 8;
|
||
}
|
||
return _pageLabel;
|
||
}
|
||
|
||
@end
|