2021-09-23 18:38:33 +08:00
|
|
|
//
|
|
|
|
// 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 "UIImageConstant.h"
|
|
|
|
///Model
|
|
|
|
#import "UserInfoModel.h"
|
|
|
|
|
|
|
|
@interface XPMineUserInfoHeaderView ()<SDCycleScrollViewDelegate, SDPhotoBrowserDelegate>
|
|
|
|
///覆盖的
|
|
|
|
@property (nonatomic,strong) UIView * coverView;
|
|
|
|
///轮播图
|
|
|
|
@property (nonatomic,strong) SDCycleScrollView *cycleScrollView;
|
|
|
|
///高斯模糊
|
|
|
|
@property (nonatomic,strong) UIVisualEffectView *effectView;
|
|
|
|
///显示当前的页数
|
|
|
|
@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.effectView];
|
|
|
|
[self addSubview:self.coverView];
|
|
|
|
[self addSubview:self.pageLabel];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
|
|
|
[self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.edges.mas_equalTo(self);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.effectView 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 [UIImage imageNamed:[UIImageConstant defalutBannerPlaceholder]];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - SDCycleScrollViewDelegate
|
|
|
|
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
|
|
|
|
self.pageLabel.text = [NSString stringWithFormat:@"%ld/%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.5;
|
|
|
|
}
|
|
|
|
return _coverView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SDCycleScrollView *)cycleScrollView {
|
|
|
|
if (!_cycleScrollView) {
|
|
|
|
_cycleScrollView = [[SDCycleScrollView alloc] init];
|
|
|
|
_cycleScrollView.backgroundColor = [UIColor clearColor];
|
|
|
|
_cycleScrollView.delegate = self;
|
|
|
|
_cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
_cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;;
|
2021-09-24 17:46:52 +08:00
|
|
|
_cycleScrollView.placeholderImage = [UIImage imageNamed:[UIImageConstant defaultAvatarPlaceholder]];
|
2021-09-23 18:38:33 +08:00
|
|
|
_cycleScrollView.autoScroll = NO;
|
|
|
|
}
|
|
|
|
return _cycleScrollView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIVisualEffectView *)effectView {
|
|
|
|
if (!_effectView) {
|
|
|
|
UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
|
|
|
|
UIVisualEffectView *view = [[UIVisualEffectView alloc]initWithEffect:beffect];
|
|
|
|
_effectView = view;
|
|
|
|
}
|
|
|
|
return _effectView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
2021-09-24 17:46:52 +08:00
|
|
|
_pageLabel.alpha = 0.1;
|
2021-09-23 18:38:33 +08:00
|
|
|
_pageLabel.layer.masksToBounds = YES;
|
|
|
|
_pageLabel.layer.cornerRadius = 8;
|
|
|
|
}
|
|
|
|
return _pageLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|