Files
peko-ios/YuMi/Modules/YMRoom/Features/Boom/RoomBoomBannerAnimation.m
2024-10-29 17:10:56 +08:00

243 lines
9.5 KiB
Objective-C

//
// RoomBoomBannerAnimation.m
// YuMi
//
// Created by P on 2024/9/27.
//
#import "RoomBoomBannerAnimation.h"
#import "RoomBoomManager.h"
#import "RoomInfoModel.h"
#import "BoomInfoModel.h"
#import "AttachmentModel.h"
#import "RoomHostDelegate.h"
#import "XPRoomViewController.h"
#import "XCCurrentVCStackManager.h"
#import "XPSkillCardPlayerManager.h"
@interface RoomBoomBannerAnimation ()
@property (nonatomic, strong) NetImageView *avatar;
@property (nonatomic, strong) NetImageView *rocket;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) Boom632Model *model;
@property (nonatomic, assign) BOOL needHandleTap;
@end
@implementation RoomBoomBannerAnimation
+ (void)display:(UIView *)superView
with:(AttachmentModel *)attachment
tapToRoom:(BOOL)handleTapToRoom
complete:(nonnull void (^)(void))complete {
if (!attachment) {
return;
}
Boom632Model *m = [Boom632Model modelWithJSON:attachment.data];
CGFloat width = KScreenWidth-32;
CGFloat height = kGetScaleWidth(90);
RoomBoomBannerAnimation *bannerView = [[RoomBoomBannerAnimation alloc] initWithFrame:CGRectMake(KScreenWidth, 80, width, height)];
bannerView.model = m;
bannerView.needHandleTap = handleTapToRoom;
[superView addSubview:bannerView];
@kWeakify(bannerView);
[UIView animateWithDuration:0.25 animations:^{
bannerView.center = CGPointMake(superView.center.x, height/2 + 80);
} completion:^(BOOL finished) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
bannerView.frame = CGRectMake(-KScreenWidth, 80, width, height);
} completion:^(BOOL finished) {
@kStrongify(bannerView);
[bannerView removeFromSuperview];
[[RoomBoomManager sharedManager] bannerDisplayEnd];
}];
});
}];
}
- (void)setModel:(Boom632Model *)model {
_model = model;
self.avatar.imageUrl = model.avatar;
self.rocket.imageUrl = model.pic;
self.titleLabel.text = [NSString stringWithFormat:@"%@%@", YMLocalizedString(@"RoomBoom_5"), model.roomTitle];
}
- (void)handleTapGo {
if (self.needHandleTap) {
// 找到當前房間
UIViewController * controllerView = [XCCurrentVCStackManager shareManager].getCurrentVC;
__block XPRoomViewController<RoomHostDelegate> *roomVC = nil;
[controllerView.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[XPRoomViewController class]]) {
[controllerView.navigationController popToRootViewControllerAnimated:NO];
roomVC = obj;
*stop = YES;
}
}];
if (roomVC) {
// 是否相同房間
if ([roomVC getRoomInfo].uid == [[XPSkillCardPlayerManager shareInstance] roomUid].integerValue) {
return;
}
__block NSString *targetRoomUid = @(self.model.roomUid).stringValue;
[TTPopup alertWithMessage:YMLocalizedString(@"Combo_10") confirmHandler:^{
[roomVC exitRoom];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[XPRoomViewController openRoom:targetRoomUid
viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
});
} cancelHandler:^{}];
} else {
[XPRoomViewController openRoom:@(self.model.roomUid).stringValue
viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
}
}
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor clearColor];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:kImage(@"boom_banner_bg")];
backgroundImageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:backgroundImageView];
[backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.bottom.mas_equalTo(self);
make.width.mas_equalTo(kGetScaleWidth(285));
}];
UIButton *goButton = [UIButton buttonWithType:UIButtonTypeCustom];
[goButton addTarget:self action:@selector(handleTapGo) forControlEvents:UIControlEventTouchUpInside];
[goButton setBackgroundImage:kImage(@"boom_banner_go") forState:UIControlStateNormal];
[self addSubview:goButton];
[goButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.bottom.mas_equalTo(self);
make.width.mas_equalTo(kGetScaleWidth(97));
}];
UIImageView *avatarWearImageView = [[UIImageView alloc] initWithImage:kImage(@"boom_banner_wear")];
avatarWearImageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:avatarWearImageView];
[avatarWearImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.bottom.mas_equalTo(self);
make.width.mas_equalTo(kGetScaleWidth(94));
}];
[self insertSubview:self.avatar belowSubview:avatarWearImageView];
[self.avatar mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(avatarWearImageView);
make.top.mas_equalTo(avatarWearImageView).offset(19);
make.width.height.mas_equalTo(kGetScaleWidth(57));
}];
[self addSubview:self.rocket];
[self.rocket mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(avatarWearImageView.mas_right);
make.centerY.mas_equalTo(backgroundImageView);
make.width.height.mas_equalTo(kGetScaleWidth(35));
}];
[self addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(38));
make.left.mas_equalTo(self.rocket.mas_right).offset(4);
make.right.mas_equalTo(goButton.mas_left);
make.height.mas_offset(17);
}];
[self addSubview:self.contentLabel];
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.titleLabel.mas_bottom);
make.left.mas_equalTo(self.rocket.mas_right).offset(4);
make.right.mas_equalTo(goButton.mas_left);
// make.height.mas_offset(17);
}];
}
return self;
}
- (NetImageConfig *)avatarConfig {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
return config;
}
- (NetImageView *)avatar {
if (!_avatar) {
_avatar = [[NetImageView alloc] initWithConfig:[self avatarConfig]];
_avatar.layer.masksToBounds = YES;
_avatar.layer.cornerRadius = 56/2;
_avatar.layer.borderColor = [UIColor whiteColor].CGColor;
_avatar.layer.borderWidth = 1;
}
return _avatar;
}
- (NetImageView *)rocket {
if (!_rocket) {
_rocket = [[NetImageView alloc] init];
_rocket.contentMode = UIViewContentModeScaleAspectFit;
}
return _rocket;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel labelInitWithText:@""
font:kFontMedium(12)
textColor:[UIColor whiteColor]];
_titleLabel.shadowColor = [UIColor grayColor];
_titleLabel.shadowOffset = CGSizeMake(2, 2);
}
return _titleLabel;
}
- (UILabel *)contentLabel {
if (!_contentLabel) {
_contentLabel = [UILabel labelInitWithText:@""
font:kFontMedium(10)
textColor:[UIColor whiteColor]];
_contentLabel.numberOfLines = 2;
NSAttributedString *as_2 = [[NSAttributedString alloc] initWithString:@"Boom"
attributes:@{NSFontAttributeName: kFontMedium(10),
NSForegroundColorAttributeName: UIColorFromRGB(0xFFE018)}];
NSAttributedString *as_3 = [[NSAttributedString alloc] initWithString:YMLocalizedString(@"RoomBoom_4")
attributes:@{NSFontAttributeName: kFontMedium(10),
NSForegroundColorAttributeName: [UIColor whiteColor]}];
NSMutableAttributedString *content = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"RoomBoom_3") attributes:@{NSFontAttributeName: kFontMedium(10), NSForegroundColorAttributeName: [UIColor whiteColor]}];
if (isMSRTL()) {
[content appendAttributedString:as_3];
} else if (isMSZH()) {
[content appendAttributedString:as_2];
[content appendAttributedString:as_3];
} else {
[content insertAttributedString:as_2 atIndex:0];
}
_contentLabel.attributedText = content;
}
return _contentLabel;
}
@end