Files
yinmeng-ios/xplan-ios/Main/Room/View/ActivityContainerView/XPRoomActivityPlayView.m
2022-10-09 16:36:26 +08:00

127 lines
4.4 KiB
Objective-C

//
// XPRoomActivityPlayView.m
// xplan-ios
//
// Created by GreenLand on 2022/9/30.
//
#import "XPRoomActivityPlayView.h"
///Third
#import <Masonry/Masonry.h>
#import "XPMacro.h"
#import "ThemeColor.h"
#import "UIImage+Utils.h"
///Model
#import "XPRoomActivityPlayModel.h"
#import "NetImageView.h"
@interface XPRoomActivityPlayView()
@property (nonatomic, strong) UIButton *moreButton;
@end
@implementation XPRoomActivityPlayView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.moreButton.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(8, 8)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.moreButton.bounds;
maskLayer.path = maskPath.CGPath;
self.moreButton.layer.mask = maskLayer;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.moreButton];
}
- (void)initSubViewConstraints {
[self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.mas_equalTo(self);
make.width.mas_equalTo(18);
}];
}
- (void)moreButtonAction:(UIButton *)sender {
if (self.frame.size.width > 18) {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomActivityPlayViewHideMorePlay)]) {
[self.delegate xPRoomActivityPlayViewHideMorePlay];
}
} else {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomActivityPlayViewShowMorePlay)]) {
[self.delegate xPRoomActivityPlayViewShowMorePlay];
}
}
}
- (void)imageTapRecognizer:(UITapGestureRecognizer *)ges {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomActivityPlayViewDidClickPlay:)]) {
XPRoomActivityPlayModel *model = self.playArray[ges.view.tag];
[self.delegate xPRoomActivityPlayViewDidClickPlay:model];
}
}
- (void)setPlayArray:(NSMutableArray *)playArray {
_playArray = playArray;
if (playArray.count) {
CGFloat itemWidth = 45;
for (int i = 0; i<playArray.count; i++) {
XPRoomActivityPlayModel *model = playArray[i];
NetImageView *imageView = [[NetImageView alloc] init];
if (model.playType == RoomActivityPlayTypeCandyTree) {
imageView.imageUrl = model.imageName;
} else {
imageView.image = [UIImage imageNamed:model.imageName];
}
imageView.tag = i;
if (i == 0) {
imageView.frame = CGRectMake(18, (53 - itemWidth ) * 0.5, itemWidth, itemWidth);
} else {
imageView.frame = CGRectMake(18 + i * (itemWidth+2), (53 - itemWidth ) * 0.5, itemWidth, itemWidth);
}
imageView.backgroundColor = UIColorRGBAlpha(0xD7D7D7, 0.2);
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapRecognizer:)];
[imageView addGestureRecognizer:tap];
[self addSubview:imageView];
}
} else {
for (UIView *view in self.subviews) {
if (view != self.moreButton) {
[view removeFromSuperview];
}
}
}
}
- (UIButton *)moreButton {
if (!_moreButton) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font = [UIFont systemFontOfSize:10];
[button addTarget:self action:@selector(moreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"更多玩法" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;//换行模式自动换行
button.titleLabel.numberOfLines = 0;
button.titleLabel.textAlignment = NSTextAlignmentCenter;
[button setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x6E36FF), UIColorFromRGB(0x31EBF7)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(18, 53)] forState:UIControlStateNormal];
_moreButton = button;
}
return _moreButton;
}
@end