240 lines
9.0 KiB
Objective-C
240 lines
9.0 KiB
Objective-C
//
|
|
// XPRoomGameInviteBannerView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by duoban on 2023/8/22.
|
|
//
|
|
|
|
#import "XPRoomGameInviteBannerView.h"
|
|
@interface XPRoomGameInviteBannerView()
|
|
///背景
|
|
@property(nonatomic,strong) UIImageView *bgImageView;
|
|
///头部图标
|
|
@property(nonatomic,strong) UIImageView *topImageView;
|
|
///头像
|
|
@property(nonatomic,strong) NetImageView *headVeiw;
|
|
///昵称
|
|
@property(nonatomic,strong) UILabel *nameView;
|
|
///局数
|
|
@property(nonatomic,strong) UILabel *inviteView;
|
|
///游戏图标
|
|
@property(nonatomic,strong) NetImageView *gameIcomView;
|
|
///游戏类型
|
|
@property(nonatomic,strong) UILabel *gameTypeView;
|
|
///立即查看
|
|
@property(nonatomic,strong) UIButton *inspectView;
|
|
//返回
|
|
@property(nonatomic,strong) UIButton *backBtn;
|
|
@end
|
|
@implementation XPRoomGameInviteBannerView
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame{
|
|
self = [super initWithFrame:frame];
|
|
if(self){
|
|
[self installUI];
|
|
[self installConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)installUI{
|
|
[self addSubview:self.bgImageView];
|
|
[self.bgImageView addSubview:self.backBtn];
|
|
[self.bgImageView addSubview:self.topImageView];
|
|
[self.bgImageView addSubview:self.headVeiw];
|
|
[self.bgImageView addSubview:self.nameView];
|
|
[self.bgImageView addSubview:self.inviteView];
|
|
[self.bgImageView addSubview:self.gameIcomView];
|
|
[self.bgImageView addSubview:self.gameTypeView];
|
|
[self.bgImageView addSubview:self.inspectView];
|
|
}
|
|
-(void)installConstraints{
|
|
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.equalTo(self).inset(kGetScaleWidth(12));
|
|
make.top.bottom.equalTo(self);
|
|
}];
|
|
[self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self.bgImageView);
|
|
make.top.mas_equalTo(kGetScaleWidth(-4));
|
|
make.width.mas_equalTo(kGetScaleWidth(122));
|
|
make.height.mas_equalTo(kGetScaleWidth(34));
|
|
}];
|
|
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.height.mas_equalTo(kGetScaleWidth(12));
|
|
make.top.mas_equalTo(kGetScaleWidth(8));
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(10));
|
|
}];
|
|
[self.headVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.height.mas_equalTo(kGetScaleWidth(48));
|
|
make.leading.mas_equalTo(kGetScaleWidth(20));
|
|
make.top.mas_equalTo(kGetScaleWidth(28));
|
|
|
|
}];
|
|
[self.inspectView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(18));
|
|
make.width.mas_equalTo(kGetScaleWidth(80));
|
|
make.height.mas_equalTo(kGetScaleWidth(34));
|
|
make.top.mas_equalTo(kGetScaleWidth(35));
|
|
}];
|
|
[self.nameView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.headVeiw.mas_top).mas_offset(kGetScaleWidth(5));
|
|
make.leading.equalTo(self.headVeiw.mas_trailing).mas_offset(kGetScaleWidth(10));
|
|
make.trailing.equalTo(self.inspectView.mas_leading).mas_offset(-kGetScaleWidth(5));
|
|
make.height.mas_equalTo(kGetScaleWidth(20));
|
|
}];
|
|
[self.inviteView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.equalTo(self.headVeiw.mas_trailing).mas_offset(kGetScaleWidth(10));
|
|
make.top.equalTo(self.nameView.mas_bottom).mas_offset(kGetScaleWidth(2));
|
|
make.height.mas_equalTo(kGetScaleWidth(17));
|
|
|
|
}];
|
|
[self.gameIcomView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.height.mas_equalTo(kGetScaleWidth(16));
|
|
make.leading.equalTo(self.inviteView.mas_trailing).mas_offset(kGetScaleWidth(4));
|
|
make.centerY.equalTo(self.inviteView);
|
|
}];
|
|
|
|
[self.gameTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.equalTo(self.gameIcomView.mas_trailing).mas_offset(kGetScaleWidth(4));
|
|
make.centerY.equalTo(self.inviteView);
|
|
make.trailing.equalTo(self.inspectView.mas_leading).mas_offset(-kGetScaleWidth(5));
|
|
}];
|
|
|
|
}
|
|
-(void)show{
|
|
[self performSelector:@selector(closeView) withObject:nil afterDelay:3];
|
|
|
|
}
|
|
-(void)closeView{
|
|
[self removeFromSuperview];
|
|
}
|
|
-(void)closeAction{
|
|
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(closeView) object:nil];
|
|
[self removeFromSuperview];
|
|
}
|
|
-(void)sendMessageBtnAction{
|
|
[self removeFromSuperview];
|
|
if(self.delegate && [self.delegate respondsToSelector:@selector(sendGameInviteMessageWithGameInfo:)]){
|
|
[self.delegate sendGameInviteMessageWithGameInfo:self.gameInfo];
|
|
}
|
|
}
|
|
-(void)setGameInfo:(UserGameInfoVo *)gameInfo{
|
|
_gameInfo = gameInfo;
|
|
_headVeiw.imageUrl = _gameInfo.fromAvatar;
|
|
_nameView.text = _gameInfo.fromNick;
|
|
_gameIcomView.imageUrl = _gameInfo.gameLogo.length > 0 ? _gameInfo.gameLogo : _gameInfo.logo;
|
|
_gameTypeView.text = _gameInfo.gameName;
|
|
_gameTypeView.text = @"拖泥带水清晨";
|
|
NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"邀请你玩 %@ 局",_gameInfo.inning] attributes:@{NSFontAttributeName:kFontRegular(12),NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
|
[textAtt addAttributes:@{NSFontAttributeName:kFontBold(12),NSForegroundColorAttributeName:[UIColor whiteColor]} range:[textAtt.string rangeOfString:_gameInfo.inning]];
|
|
_inviteView.attributedText = textAtt;
|
|
}
|
|
-(UIImage *)setBlurImage:(UIImage *)image{
|
|
|
|
|
|
CIContext *context = [CIContext contextWithOptions:nil];
|
|
CIImage * sourceImage = [CIImage imageWithCGImage:image.CGImage];//将图片转换成CIImage
|
|
|
|
///图片仿射滤镜
|
|
|
|
CIFilter * clamp = [CIFilter filterWithName:@"CIAffineClamp"];//设置绘制类型
|
|
|
|
[clamp setValue:sourceImage forKey:kCIInputImageKey];//设置要绘制的图片
|
|
|
|
CIImage *clampResult = [clamp valueForKey:kCIOutputImageKey];
|
|
|
|
///高斯模糊滤镜
|
|
|
|
CIFilter* gaussianBlur = [CIFilter filterWithName:@"CIGaussianBlur"];
|
|
|
|
[gaussianBlur setValue:clampResult forKey:kCIInputImageKey];
|
|
|
|
[gaussianBlur setValue:[NSNumber numberWithFloat:1] forKey:@"inputRadius"];//设置模糊值
|
|
|
|
CIImage * gaussianBlurResult = [gaussianBlur valueForKey:kCIOutputImageKey];
|
|
|
|
///转化获取图片
|
|
|
|
CGImageRef cgImage = [context createCGImage:gaussianBlurResult fromRect:[sourceImage extent]];
|
|
|
|
UIImage * resultImage = [UIImage imageWithCGImage:cgImage];
|
|
return resultImage;
|
|
|
|
}
|
|
#pragma mark - 懒加载
|
|
- (UIImageView *)bgImageView{
|
|
if(!_bgImageView){
|
|
_bgImageView = [UIImageView new];
|
|
_bgImageView.userInteractionEnabled = YES;
|
|
_bgImageView.image = [self setBlurImage:kImage(@"room_game_invite_banner_bg")];
|
|
}
|
|
return _bgImageView;
|
|
}
|
|
- (UIImageView *)topImageView{
|
|
if(!_topImageView){
|
|
_topImageView = [UIImageView new];
|
|
_topImageView.image = kImage(@"room_game_invite_banner_top");
|
|
_topImageView.userInteractionEnabled = YES;
|
|
}
|
|
return _topImageView;
|
|
}
|
|
- (UIButton *)backBtn{
|
|
if(!_backBtn){
|
|
_backBtn = [UIButton new];
|
|
[_backBtn setImage:kImage(@"room_game_invite_banner_back") forState:UIControlStateNormal];
|
|
[_backBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
|
[_backBtn addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _backBtn;
|
|
}
|
|
- (NetImageView *)headVeiw{
|
|
if(!_headVeiw){
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
|
config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
|
|
_headVeiw = [[NetImageView alloc]initWithConfig:config];
|
|
_headVeiw.layer.cornerRadius = kGetScaleWidth(48)/2;
|
|
_headVeiw.layer.masksToBounds = YES;
|
|
}
|
|
return _headVeiw;
|
|
}
|
|
- (UILabel *)nameView{
|
|
if(!_nameView){
|
|
_nameView = [UILabel labelInitWithText:@"" font:kFontSemibold(14) textColor:[UIColor whiteColor]];
|
|
}
|
|
return _nameView;
|
|
}
|
|
- (UILabel *)inviteView{
|
|
if(!_inviteView){
|
|
_inviteView = [UILabel new];
|
|
|
|
}
|
|
return _inviteView;
|
|
}
|
|
- (NetImageView *)gameIcomView{
|
|
if(!_gameIcomView){
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
|
config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
|
|
_gameIcomView = [[NetImageView alloc]initWithConfig:config];
|
|
_gameIcomView.layer.masksToBounds = YES;
|
|
}
|
|
return _gameIcomView;
|
|
}
|
|
- (UILabel *)gameTypeView{
|
|
if(!_gameTypeView){
|
|
_gameTypeView = [UILabel labelInitWithText:@"" font:kFontSemibold(14) textColor:UIColorFromRGB(0xFFD46C)];
|
|
}
|
|
return _gameTypeView;
|
|
}
|
|
- (UIButton *)inspectView{
|
|
if(!_inspectView){
|
|
_inspectView = [UIButton new];
|
|
[_inspectView setBackgroundImage:kImage(@"room_game_invite_banner_inspectView") forState:UIControlStateNormal];
|
|
[_inspectView setTitle:@"立即查看" forState:UIControlStateNormal];
|
|
[_inspectView setTitleColor:UIColorFromRGB(0x695CEB) forState:UIControlStateNormal];
|
|
_inspectView.titleLabel.font = kFontMedium(12);
|
|
[_inspectView addTarget:self action:@selector(sendMessageBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _inspectView;
|
|
}
|
|
@end
|
|
|