123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // webRtcPlayerViewController+AdjustBtnFrame.m
- // 双子星云手机
- //
- // Created by xd h on 2024/9/5.
- //
- #import "webRtcPlayerViewController+AdjustBtnFrame.h"
- #import <objc/runtime.h>
- @implementation webRtcPlayerViewController(AdjustBtnFrame)
- @dynamic adjustTime;
- - (void)setAdjustTime:(NSInteger)adjustTime {
- objc_setAssociatedObject(self, @selector(adjustTime), @(adjustTime), OBJC_ASSOCIATION_ASSIGN);
- }
- - (NSInteger)adjustTime {
- NSNumber *adjustTimeNumber = objc_getAssociatedObject(self, @selector(adjustTime));
-
- return [adjustTimeNumber integerValue];
- }
- #pragma mark 悬浮球3s后自动靠边隐藏
- // 控制按钮3s后 自动靠边算法
- - (void)adjustPlayerViewControlBtnFrame1 {
-
- CGFloat margin = 60/2.0;
- CGFloat W_H = 60;
- self.controlBtn.alpha = 0.5;
-
- CGPoint centerPoint = self.controlBtn.center;
- // HLog(@"云手机推流界面 控制按钮中点%@",NSStringFromCGPoint(centerPoint));
-
- if (self.mediaStream.hw_w > self.mediaStream.hw_h){//横屏
-
- CGFloat screen_W = SCREEN_W>SCREEN_H?SCREEN_W:SCREEN_H;/*实际较大的数字*/
- CGFloat screen_H = (SCREEN_W<SCREEN_H?SCREEN_W:SCREEN_H);/*实际较小的数字*/
-
- CGFloat centerY = screen_W*0.5;
- CGFloat value1Y = centerY - centerPoint.x;
- //CGFloat adaptValue = (SCREEN_W - mPlayerView.glkshowImageView.hw_h)*0.5; // 补偿刘海屏上下黑边
-
- if (value1Y >= 0) { // 左边
- HLog(@"云手机推流界面 靠左边");
- self.controlBtn.hw_x = - W_H + margin + safeArea;
- }else { // 右边
- HLog(@"云手机推流界面 靠右边");
- self.controlBtn.hw_x = screen_W - margin;
- }
-
- if (centerPoint.y < 0){
- self.controlBtn.hw_y = 0;
- }else if (self.controlBtn.hw_y > screen_H){
- self.controlBtn.hw_y = screen_H - W_H;
- }
-
- }else{//竖屏
- //竖屏靠边状态 不处理
- if(centerPoint.x == 0 || centerPoint.x == SCREEN_W){
- return;
- }
-
- CGFloat centerX = SCREEN_W*0.5;
- CGFloat value1X = centerX - centerPoint.x;
-
- if (value1X >= 0) { // 左边
- HLog(@"云手机推流界面 靠左边");
- self.controlBtn.hw_x = - W_H + margin;
- }else { // 右边
- HLog(@"云手机推流界面 靠右边");
- self.controlBtn.hw_x = SCREEN_W - margin;
- }
-
- //原来Y坐标逻辑
- // if (self.controlBtn.y < margin){
- // self.controlBtn.y = margin;
- // }else if (self.controlBtn.y > self.mediaStream.height - margin - W_H){
- // self.controlBtn.y = self.mediaStream.height - margin - W_H;
- // }
-
- //20240905 Y坐标逻辑
- // if(centerPoint.y < (self.mediaStream.hw_y + margin)){//在屏幕上方 超出了推流页
- // self.controlBtn.hw_y = self.mediaStream.hw_y + margin;
- // }
- // else if(centerPoint.y > (self.mediaStream.hw_max_y)
- // && (SCREEN_H - centerPoint.y) < safeArea){//在屏幕下方 超出了推流页
- // self.controlBtn.hw_y = self.mediaStream.hw_h - margin;
- // }
- // else{//在屏幕中间
- // //Y 不变
- // }
- }
- didAdjusBtnType = YES;
- HLog(@"云手机推流界面 控制按钮中点%@",NSStringFromCGPoint(self.controlBtn.center));
- }
- // 1、悬浮球3s后 自动靠边隐藏
- - (void)extensionAdjustBtnFrameCheckAdjustTime {
- self.adjustTime--;
-
- if(self.adjustTime < 0){
- self.adjustTime = 0;
- }
-
- //if (self.adjustTime == 0 && !didAdjusBtnType)
- if (self.adjustTime == 0)
- {
- // HLog(@"云手机圆形浮标自动隐藏倒计时 3s倒计时结束");
- [self adjustPlayerViewControlBtnFrame1];
- }else {
- // HLog(@"云手机圆形浮标自动隐藏倒计时:%zd", self.adjustTime);
- }
- }
- #pragma mark 悬浮标拖拽
- - (void)controlBtnPanGestureCallback:(UIPanGestureRecognizer *)panGesture{
- self.controlBtn.alpha = 1;
- CGRect frame = self.controlBtn.frame;
- switch (panGesture.state) {
- case UIGestureRecognizerStateBegan:{
- startFrame = self.controlBtn.frame;
- break;
- }
- case UIGestureRecognizerStateChanged:{
- self.adjustTime = 2;
- CGPoint translatedPoint = [panGesture translationInView:self.mediaStream];/*KXLY*/
- CGRect frame = self.controlBtn.frame;
- frame.origin.x = translatedPoint.x + startFrame.origin.x;
- frame.origin.y = translatedPoint.y + startFrame.origin.y;
- self.controlBtn.frame = frame;
-
- // HLog(@"\n--(%f,%f)--controlBtn.frame--X-%f",translatedPoint.x,translatedPoint.x,controlBtn.frame.origin.x);
-
- break;
- }
- case UIGestureRecognizerStateEnded:{
- self.adjustTime = 1;
- // HLog(@"云手机推流界面 控制按钮拖动手势结束");
- /*防止控制器移出屏幕*/
- if (frame.origin.x < 10.f/2.f){
- frame.origin.x = 10.f/2.f;
- }
- if (frame.origin.y < 10.f/2.f + H_STATE_BAR){
- frame.origin.y = 10.f/2.f + H_STATE_BAR;
- }
- if (frame.size.width + frame.origin.x + 10.f/2.f > self.view.hw_w){
- frame.origin.x = self.view.hw_w - 10.f/2.f - frame.size.width;
- }
- if (frame.size.height + frame.origin.y + 10.f/2.f > self.view.hw_h){
- frame.origin.y = self.view.hw_h - 10.f/2.f - frame.size.height;
- }
-
- self.controlBtn.frame = frame;
- }
- break;
- case UIGestureRecognizerStateCancelled: {
- /*防止控制器移出屏幕*/
- if (frame.origin.x < 10.f/2.f){
- frame.origin.x = 10.f/2.f;
- }
- if (frame.origin.y < 10.f/2.f + H_STATE_BAR){
- frame.origin.y = 10.f/2.f + H_STATE_BAR;
- }
- if (frame.size.width + frame.origin.x + 10.f/2.f > self.view.hw_w){
- frame.origin.x = self.view.hw_w - 10.f/2.f - frame.size.width;
- }
- if (frame.size.height + frame.origin.y + 10.f/2.f > self.view.hw_h){
- frame.origin.y = self.view.hw_h - 10.f/2.f - frame.size.height;
- }
-
- self.controlBtn.frame = frame;
-
- break;
- }
- default:
- break;
- }
- }
- @end
|