174 lines
6.2 KiB
Objective-C
174 lines
6.2 KiB
Objective-C
//
|
||
// QXDrifNobilityJoinRoomView.m
|
||
// QXLive
|
||
//
|
||
// Created by 启星 on 2025/11/11.
|
||
//
|
||
|
||
#import "QXDrifNobilityJoinRoomView.h"
|
||
//nobility_drif_join_room_bg
|
||
@interface QXDrifNobilityJoinRoomView()
|
||
@property (nonatomic,weak)UIView* containerView;
|
||
@property (nonatomic,assign)BOOL isPlaying;
|
||
@property (nonatomic,assign)BOOL isClose;
|
||
@property (nonatomic,assign)BOOL isBackgroud;
|
||
@end
|
||
@implementation QXDrifNobilityJoinRoomView
|
||
|
||
- (instancetype)init
|
||
{
|
||
self = [super init];
|
||
if (self) {
|
||
self.frame = CGRectMake(SCREEN_WIDTH, 340, 208, 60);
|
||
BOOL isClose = [[NSUserDefaults standardUserDefaults] boolForKey:kIsCloseDrifNobility];
|
||
self.isClose = isClose;
|
||
[self initSubviews];
|
||
}
|
||
return self;
|
||
}
|
||
+(instancetype)shareView{
|
||
static QXDrifNobilityJoinRoomView *manager = nil;
|
||
static dispatch_once_t predicate;
|
||
dispatch_once(&predicate, ^{
|
||
manager = [[QXDrifNobilityJoinRoomView alloc] init];
|
||
});
|
||
return manager;
|
||
}
|
||
- (void)setupDisplayViewInContainer:(UIView *)container {
|
||
self.containerView = container;
|
||
}
|
||
-(void)initSubviews{
|
||
self.bgImageView = [[UIImageView alloc] init];
|
||
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
|
||
[self addSubview:self.bgImageView];
|
||
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.width.mas_equalTo(208);
|
||
make.height.mas_equalTo(60);
|
||
make.centerY.centerX.equalTo(self);
|
||
}];
|
||
|
||
self.titleLabel = [[UILabel alloc] init];
|
||
self.titleLabel.font = [UIFont systemFontOfSize:12];
|
||
self.titleLabel.textColor = RGB16(0xFFFFFF);
|
||
[self addSubview:self.titleLabel];;
|
||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.equalTo(self.bgImageView).offset(57);
|
||
make.centerY.equalTo(self.bgImageView);
|
||
}];
|
||
self.userInteractionEnabled = YES;
|
||
// MJWeakSelf
|
||
// [self addTapBlock:^(id _Nonnull obj) {
|
||
// if ([weakSelf.model.room_id isExist]) {
|
||
// [[QXGlobal shareGlobal] joinRoomWithRoomId:weakSelf.model.room_id isRejoin:NO navagationController:weakSelf.viewController.navigationController];
|
||
// }
|
||
// }];
|
||
}
|
||
-(void)addNobilityUserModel:(QXRoomChatListModel *)model{
|
||
if (self.isClose) {
|
||
return;
|
||
}
|
||
[self.dataArray addObject:model];
|
||
[self giftAction];
|
||
}
|
||
|
||
|
||
-(void)giftAction{
|
||
if (self.isPlaying) {
|
||
return;
|
||
}
|
||
if (self.isBackgroud) {
|
||
return;
|
||
}
|
||
MJWeakSelf
|
||
[QXDrifNobilityJoinRoomView shareView].isPlaying = YES;
|
||
[QXDrifNobilityJoinRoomView shareView].model = [QXDrifNobilityJoinRoomView shareView].dataArray.firstObject;
|
||
// [KEYWINDOW addSubview:[QXDrifNobilityJoinRoomView shareView]];
|
||
[self.containerView addSubview:[QXDrifNobilityJoinRoomView shareView]];
|
||
// [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
|
||
// [QXDrifNobilityJoinRoomView shareView].x = (SCREEN_WIDTH-ScaleWidth(358))/2;
|
||
// } completion:^(BOOL finished) {
|
||
// [weakSelf performSelector:@selector(dissmissAnimate) afterDelay:5];
|
||
// }];
|
||
[QXDrifNobilityJoinRoomView shareView].alpha = 0;
|
||
// 第一阶段:快速进入(0.3秒)
|
||
[UIView animateWithDuration:0.3
|
||
delay:0
|
||
options:UIViewAnimationOptionCurveEaseOut
|
||
animations:^{
|
||
[QXDrifNobilityJoinRoomView shareView].x = 36;
|
||
[QXDrifNobilityJoinRoomView shareView].alpha = 1;
|
||
} completion:^(BOOL finished) {
|
||
if (finished) {
|
||
// 第二阶段:非常慢速停留
|
||
[UIView animateWithDuration:1.8
|
||
delay:0
|
||
options:UIViewAnimationOptionCurveLinear
|
||
animations:^{
|
||
// 微小的水平移动,创造缓慢移动效果
|
||
[QXDrifNobilityJoinRoomView shareView].x = 16;
|
||
} completion:^(BOOL finished) {
|
||
if (finished) {
|
||
[self dissmissAnimate];
|
||
}
|
||
}];
|
||
}
|
||
}];
|
||
}
|
||
-(void)dissmissAnimate{
|
||
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
|
||
[QXDrifNobilityJoinRoomView shareView].x = -SCREEN_WIDTH;
|
||
} completion:^(BOOL finished) {
|
||
[QXDrifNobilityJoinRoomView shareView].x = SCREEN_WIDTH;
|
||
[[QXDrifNobilityJoinRoomView shareView] removeFromSuperview];
|
||
[[QXDrifNobilityJoinRoomView shareView].dataArray removeFirstObject];
|
||
[QXDrifNobilityJoinRoomView shareView].isPlaying = NO;
|
||
if ([QXDrifNobilityJoinRoomView shareView].dataArray.count>0) {
|
||
[[QXDrifNobilityJoinRoomView shareView] giftAction];
|
||
}
|
||
}];
|
||
}
|
||
|
||
-(void)setModel:(QXRoomChatListModel *)model{
|
||
_model = model;
|
||
self.titleLabel.text = model.FromUserInfo.enter_text;
|
||
[self.bgImageView sd_setImageWithURL:[NSURL URLWithString:model.FromUserInfo.enter_image]];
|
||
}
|
||
-(void)drifPopIsClose:(BOOL)isClose{
|
||
_isClose = isClose;
|
||
self.hidden = self.isClose;
|
||
[[NSUserDefaults standardUserDefaults] setBool:isClose forKey:kIsCloseDrifNobility];
|
||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
if (isClose) {
|
||
[QXDrifNobilityJoinRoomView shareView].x = SCREEN_WIDTH;
|
||
[[QXDrifNobilityJoinRoomView shareView] removeFromSuperview];
|
||
[[QXDrifNobilityJoinRoomView shareView].dataArray removeAllObjects];
|
||
[QXDrifNobilityJoinRoomView shareView].isPlaying = NO;
|
||
}
|
||
}
|
||
-(void)dirfViewDidToBackground{
|
||
self.isBackgroud = YES;
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[QXDrifNobilityJoinRoomView shareView].x = SCREEN_WIDTH;
|
||
[[QXDrifNobilityJoinRoomView shareView] removeFromSuperview];
|
||
[[QXDrifNobilityJoinRoomView shareView].dataArray removeAllObjects];
|
||
[QXDrifNobilityJoinRoomView shareView].isPlaying = NO;
|
||
});
|
||
}
|
||
|
||
-(void)dirfViewBecomeToFront{
|
||
self.isBackgroud = NO;
|
||
if ([QXDrifNobilityJoinRoomView shareView].isPlaying == NO) {
|
||
[QXDrifNobilityJoinRoomView shareView].x = SCREEN_WIDTH;
|
||
[[QXDrifNobilityJoinRoomView shareView] removeFromSuperview];
|
||
}
|
||
}
|
||
|
||
-(NSMutableArray *)dataArray{
|
||
if (!_dataArray) {
|
||
_dataArray = [NSMutableArray array];
|
||
}
|
||
return _dataArray;
|
||
}
|
||
|
||
@end
|