125 lines
5.3 KiB
Objective-C
125 lines
5.3 KiB
Objective-C
//
|
||
// QXMiniRoomView.m
|
||
// QXLive
|
||
//
|
||
// Created by 启星 on 2025/6/25.
|
||
//
|
||
|
||
#import "QXMiniRoomView.h"
|
||
@interface QXMiniRoomView()
|
||
@property (nonatomic,strong)UIImageView *bgImageView;
|
||
@property (nonatomic,strong)UIImageView *roomCoverImageView;
|
||
@property (nonatomic,strong)UIImageView *bgRoomCoverImageView;
|
||
@property (nonatomic,strong)UIButton *closeBtn;
|
||
@property (nonatomic,strong)UIVisualEffectView *blurView;
|
||
@end
|
||
|
||
@implementation QXMiniRoomView
|
||
- (instancetype)init
|
||
{
|
||
self = [super init];
|
||
if (self) {
|
||
self.frame = CGRectMake(SCREEN_WIDTH-ScaleWidth(80), SCREEN_HEIGHT-200, ScaleWidth(80), ScaleWidth(44));
|
||
[self initSubviews];
|
||
}
|
||
return self;
|
||
}
|
||
|
||
-(void)initSubviews{
|
||
self.bgRoomCoverImageView = [[UIImageView alloc] initWithFrame:self.bounds];
|
||
self.bgRoomCoverImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
self.bgRoomCoverImageView.clipsToBounds = YES;
|
||
[self addSubview:self.bgRoomCoverImageView];
|
||
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
|
||
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:effect];
|
||
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:effect];
|
||
UIVisualEffectView *vibrancyView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
|
||
[blurView.contentView addSubview:vibrancyView];
|
||
self.blurView = blurView;
|
||
[self.bgRoomCoverImageView addSubview:blurView];
|
||
blurView.frame = self.bgRoomCoverImageView.bounds;
|
||
vibrancyView.frame = self.bgRoomCoverImageView.bounds;
|
||
|
||
|
||
self.bgImageView = [[UIImageView alloc] initWithFrame:self.bounds];
|
||
self.bgImageView.image = [UIImage imageNamed:@"mini_room_bg"];
|
||
[self addSubview:self.bgImageView];
|
||
[self addRoundedCornersWithRadius:ScaleWidth(44) byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomLeft)];
|
||
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
|
||
[self addGestureRecognizer:panRecognizer];
|
||
|
||
|
||
self.roomCoverImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9, (ScaleWidth(44)-ScaleWidth(26))/2, ScaleWidth(26), ScaleWidth(26))];
|
||
self.roomCoverImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
self.roomCoverImageView.clipsToBounds = YES;
|
||
[self.roomCoverImageView addRoundedCornersWithRadius:ScaleWidth(13)];
|
||
|
||
|
||
|
||
// [blurView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
// make.left.right.top.bottom.equalTo(self.photoImageView);
|
||
// }];
|
||
// [vibrancyView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
// make.left.right.top.bottom.equalTo(blurView);
|
||
// }];
|
||
|
||
|
||
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
|
||
//旋转角度
|
||
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI];
|
||
//每次旋转的时间(单位秒)
|
||
rotationAnimation.duration = 4;
|
||
rotationAnimation.cumulative = YES;
|
||
rotationAnimation.removedOnCompletion = NO;
|
||
//重复旋转的次数,如果你想要无数次,那么设置成MAXFLOAT
|
||
rotationAnimation.repeatCount = MAXFLOAT;
|
||
[self.roomCoverImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
|
||
MJWeakSelf
|
||
[self.roomCoverImageView addTapBlock:^(id _Nonnull obj) {
|
||
[weakSelf.layer removeAnimationForKey:@"rotationAnimation"];
|
||
[weakSelf removeFromSuperview];
|
||
[[QXGlobal shareGlobal] joinRoomWithRoomId:weakSelf.roomId isRejoin:YES navagationController:(UINavigationController*)KEYWINDOW.rootViewController];
|
||
}];
|
||
[self addSubview:self.roomCoverImageView];
|
||
|
||
self.closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width-ScaleWidth(30)-12, 0, ScaleWidth(30), ScaleWidth(44))];
|
||
UIImage *close = [[UIImage imageNamed:@"room_close"] imageByTintColor:RGB16(0x333333)];
|
||
[self.closeBtn setImage:close forState:(UIControlStateNormal)];
|
||
[self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
[self addSubview:self.closeBtn];
|
||
}
|
||
-(void)show{
|
||
[KEYWINDOW.rootViewController.view addSubview:self];
|
||
}
|
||
|
||
-(void)setRoomCoverImage:(NSString *)roomCoverImage{
|
||
_roomCoverImage = roomCoverImage;
|
||
[self.roomCoverImageView sd_setImageWithURL:[NSURL URLWithString:roomCoverImage]];
|
||
[self.bgRoomCoverImageView sd_setImageWithURL:[NSURL URLWithString:roomCoverImage]];
|
||
}
|
||
|
||
-(void)closeAction{
|
||
[self.layer removeAnimationForKey:@"rotationAnimation"];
|
||
[self removeFromSuperview];
|
||
[[QXGlobal shareGlobal] quitRoomWithRoomId:self.roomId];
|
||
}
|
||
|
||
-(void)handlePan:(UIPanGestureRecognizer*)recognizer{
|
||
if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||
NSLog(@"拖动结束");
|
||
}
|
||
CGPoint translation = [recognizer translationInView:self.viewController.view];
|
||
CGPoint panCenter = CGPointMake(recognizer.view.center.x + translation.x,
|
||
recognizer.view.center.y + translation.y);
|
||
if (panCenter.y < kSafeAreaTop || panCenter.y> SCREEN_HEIGHT-kSafeAreaBottom) {
|
||
return;
|
||
}
|
||
|
||
|
||
recognizer.view.center = CGPointMake(SCREEN_WIDTH-ScaleWidth(80)/2,
|
||
recognizer.view.center.y + translation.y);
|
||
[recognizer setTranslation:CGPointZero inView:self.viewController.view];
|
||
}
|
||
|
||
@end
|