158 lines
6.2 KiB
Objective-C
158 lines
6.2 KiB
Objective-C
//
|
|
// PIRoomActivityWebView.m
|
|
// YuMi
|
|
//
|
|
// Created by duoban on 2023/11/15.
|
|
//
|
|
|
|
#import "PIRoomActivityWebView.h"
|
|
#import "PIRoomActivityWebCell.h"
|
|
#import "XPWebViewController.h"
|
|
#define kWebViewScale ((CGFloat)KScreenHeight / (CGFloat)812)
|
|
@interface PIRoomActivityWebView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
|
@property(nonatomic,strong) UIButton *pi_backBtn;
|
|
@property(nonatomic,strong) UIView *bgView;
|
|
@property(nonatomic,strong) UICollectionView *collectionView;
|
|
|
|
///加入h5
|
|
@property (nonatomic, strong) XPWebViewController *webVC;
|
|
@property(nonatomic,assign) NSInteger path;
|
|
@end
|
|
@implementation PIRoomActivityWebView
|
|
-(instancetype)initWithFrame:(CGRect)frame{
|
|
self = [super initWithFrame:frame];
|
|
if(self){
|
|
[self installUI];
|
|
[self installConstraints];
|
|
@kWeakify(self);
|
|
self.webVC.CloseWebViewBlock = ^(BOOL result) {
|
|
@kStrongify(self);
|
|
[self dissViewAction];
|
|
};
|
|
}
|
|
return self;
|
|
}
|
|
-(void)installUI{
|
|
[self addSubview:self.pi_backBtn];
|
|
[self addSubview:self.bgView];
|
|
[self.bgView addSubview:self.collectionView];
|
|
[self.bgView addSubview:self.webVC.view];
|
|
|
|
}
|
|
-(void)installConstraints{
|
|
[self.pi_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self);
|
|
}];
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.bottom.equalTo(self);
|
|
make.height.mas_equalTo(643 * kWebViewScale);
|
|
}];
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.equalTo(self.bgView);
|
|
make.height.mas_equalTo(kGetScaleWidth(42));
|
|
make.top.mas_equalTo(kGetScaleWidth(10));
|
|
}];
|
|
[self.webVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.bottom.equalTo(self.bgView);
|
|
make.top.mas_equalTo(kGetScaleWidth(60));
|
|
}];
|
|
}
|
|
#pragma mark - UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
return self.infoList.count;
|
|
}
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
PIRoomActivityWebCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([PIRoomActivityWebCell class]) forIndexPath:indexPath];
|
|
cell.infoModel = [self.infoList safeObjectAtIndex1:indexPath.row];
|
|
cell.pi_isChoose = self.path == indexPath.row;
|
|
return cell;
|
|
}
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
ActivityInfoModel *model = [_infoList safeObjectAtIndex1:indexPath.row];
|
|
self.webVC.url = model.skipUri;
|
|
self.path = indexPath.row;
|
|
[self.collectionView reloadData];
|
|
}
|
|
-(void)dissViewAction{
|
|
[UIView animateWithDuration:0.2 animations:^{
|
|
self.frame = CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight);
|
|
}completion:^(BOOL finished) {
|
|
[self removeFromSuperview];
|
|
}];
|
|
}
|
|
- (void)setRoomUid:(NSString *)roomUid{
|
|
_roomUid = roomUid;
|
|
self.webVC.roomUid = _roomUid;
|
|
}
|
|
- (void)setUrl:(NSString *)url{
|
|
_url = url;
|
|
self.webVC.url = _url;
|
|
}
|
|
-(void)setInfoList:(NSMutableArray *)infoList{
|
|
_infoList = infoList;
|
|
for (int i = 0; i < _infoList.count; i++) {
|
|
ActivityInfoModel *model = _infoList[i];
|
|
if([model.skipUri isEqualToString:_url]){
|
|
self.path = i;
|
|
break;
|
|
}
|
|
}
|
|
[self.collectionView reloadData];
|
|
[self.collectionView.superview layoutIfNeeded];
|
|
if(_infoList.count > self.path && self.path > 3){
|
|
UICollectionViewLayoutAttributes *layoutAttributes = [self.collectionView.collectionViewLayout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForRow:self.path - 3 inSection:0]];
|
|
// 滑动
|
|
CGPoint poiot = CGPointMake(layoutAttributes.frame.origin.x - kGetScaleWidth(10), layoutAttributes.frame.origin.y);
|
|
[self.collectionView setContentOffset:poiot animated:YES];
|
|
}
|
|
|
|
}
|
|
#pragma mark - 懒加载
|
|
- (UICollectionView *)collectionView{
|
|
if (!_collectionView) {
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.minimumLineSpacing = kGetScaleWidth(8);
|
|
layout.minimumInteritemSpacing = kGetScaleWidth(8);
|
|
layout.itemSize = CGSizeMake(kGetScaleWidth(90), kGetScaleWidth(42));
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, kGetScaleWidth(8), 0, kGetScaleWidth(8));
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_collectionView.dataSource = self;
|
|
_collectionView.delegate = self;
|
|
_collectionView.showsVerticalScrollIndicator = NO;
|
|
_collectionView.showsHorizontalScrollIndicator = NO;
|
|
_collectionView.backgroundColor = [UIColor clearColor];
|
|
[_collectionView registerClass:[PIRoomActivityWebCell class] forCellWithReuseIdentifier:NSStringFromClass([PIRoomActivityWebCell class])];
|
|
|
|
}
|
|
return _collectionView;
|
|
}
|
|
- (XPWebViewController *)webVC {
|
|
if (_webVC == nil) {
|
|
_webVC = [[XPWebViewController alloc] init];
|
|
_webVC.isProperty = YES;
|
|
_webVC.view.backgroundColor = [UIColor clearColor];
|
|
CGFloat heigth = 643 * kWebViewScale - kGetScaleWidth(60);
|
|
[_webVC.view setCornerWithLeftTopCorner:kGetScaleWidth(10) rightTopCorner:kGetScaleWidth(10) bottomLeftCorner:0 bottomRightCorner:0 size:CGSizeMake(KScreenWidth, heigth)];
|
|
}
|
|
return _webVC;
|
|
}
|
|
|
|
- (UIView *)bgView{
|
|
if(!_bgView){
|
|
_bgView = [UIView new];
|
|
_bgView.backgroundColor = UIColorFromRGB(0x262629);
|
|
|
|
[_bgView setCornerWithLeftTopCorner:kGetScaleWidth(8) rightTopCorner:kGetScaleWidth(8) bottomLeftCorner:0 bottomRightCorner:0 size:CGSizeMake(KScreenWidth,642 *kWebViewScale)];
|
|
}
|
|
return _bgView;
|
|
}
|
|
- (UIButton *)pi_backBtn{
|
|
if(!_pi_backBtn){
|
|
_pi_backBtn = [UIButton new];
|
|
[_pi_backBtn addTarget:self action:@selector(dissViewAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _pi_backBtn;
|
|
}
|
|
@end
|