// // QXCabinMovieView.m // QXLive // // Created by 启星 on 2025/7/7. // #import "QXCabinMovieView.h" #import "AppDelegate.h" @interface QXCabinMovieView() @property (nonatomic,strong)UIButton *fullScreenBtn; @property (nonatomic,strong)UIPanGestureRecognizer *panRecognizer; @property (nonatomic,strong)QXCabinMovieControlView *controlView; @end @implementation QXCabinMovieView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(12, NavContentHeight, 280, 160); self.backgroundColor = RGB16(0x333333); [self initSubviews]; self.isFullScreen = NO; } return self; } -(void)initSubviews{ self.panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self addGestureRecognizer:self.panRecognizer]; self.videoView = [[UIView alloc] initWithFrame:self.bounds]; [self addSubview:self.videoView]; self.fullScreenBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width-40, self.height-40, 40, 40)]; [self.fullScreenBtn setImage:[UIImage imageNamed:@"room_full_screen"] forState:(UIControlStateNormal)]; [self.fullScreenBtn addTarget:self action:@selector(fullAction) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.fullScreenBtn]; // [self.fullScreenBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.bottom.right.equalTo(self); // make.size.mas_equalTo(CGSizeMake(40, 40)); // }]; self.controlView.hidden = YES; [self addSubview:self.controlView]; } -(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.x-214/2 <= 0 || panCenter.x+214/2 >= SCREEN_WIDTH || panCenter.y < kSafeAreaTop || panCenter.y> SCREEN_HEIGHT-kSafeAreaBottom) { return; } recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); [recognizer setTranslation:CGPointZero inView:self.viewController.view]; } -(void)fullAction{ AppDelegate *delegate = (AppDelegate*)[UIApplication sharedApplication].delegate; delegate.allowRotate = 1; [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight) forKey:@"orientation"]; [UIViewController attemptRotationToDeviceOrientation]; self.frame = CGRectMake(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH); self.videoView.frame = self.bounds; [self.viewController.view addSubview:self.controlView]; self.fullScreenBtn.hidden = YES; self.controlView.hidden = NO; self.isFullScreen = YES; } -(QXCabinMovieControlView *)controlView{ if (!_controlView) { _controlView = [[QXCabinMovieControlView alloc] init]; MJWeakSelf _controlView.returnBlock = ^{ [weakSelf resetView]; }; } return _controlView; } -(void)resetView{ AppDelegate *delegate = (AppDelegate*)[UIApplication sharedApplication].delegate; delegate.allowRotate = 0; [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"]; //刷新 [UIViewController attemptRotationToDeviceOrientation]; self.frame = CGRectMake(12, NavContentHeight, 280, 160); self.videoView.frame = self.bounds; self.fullScreenBtn.frame = CGRectMake(self.width-40, self.height-40, 40, 40); self.controlView.hidden = YES; self.fullScreenBtn.hidden = NO; self.isFullScreen = NO; } @end @implementation QXCabinMovieControlView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);; [self initSubviews]; } return self; } -(void)initSubviews{ self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 95)]; self.returnBtn = [UIButton buttonWithType:0]; [self.returnBtn setImage:[[UIImage imageNamed:@"back"] imageByTintColor:UIColor.whiteColor] forState:0]; // self.returnBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [self.returnBtn addTarget:self action:@selector(returnBtnClick) forControlEvents:UIControlEventTouchUpInside]; self.returnBtn.frame = CGRectMake(30, 10, 45, 45); [self.topView addSubview:self.returnBtn]; [self addSubview:self.topView]; } -(void)returnBtnClick{ if (self.returnBlock) { self.returnBlock(); } } @end