|
@@ -0,0 +1,179 @@
|
|
|
+//
|
|
|
+// 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 centerY = self.mediaStream.hw_h*0.5;
|
|
|
+ CGFloat value1Y = centerY - centerPoint.y;
|
|
|
+ //CGFloat adaptValue = (SCREEN_W - mPlayerView.glkshowImageView.hw_h)*0.5; // 补偿刘海屏上下黑边
|
|
|
+
|
|
|
+ if (value1Y >= 0) { // 左边
|
|
|
+ HLog(@"云手机推流界面 靠上边");
|
|
|
+ self.controlBtn.hw_y = - W_H + margin;
|
|
|
+ }else { // 右边
|
|
|
+ HLog(@"云手机推流界面 靠下边");
|
|
|
+ self.controlBtn.hw_y = SCREEN_H - margin;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (self.controlBtn.hw_x < margin){
|
|
|
+ self.controlBtn.hw_x = margin;
|
|
|
+ }else if (self.controlBtn.hw_x > self.mediaStream.hw_w - margin - W_H){
|
|
|
+ self.controlBtn.hw_x = self.mediaStream.hw_w - margin - 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 不变
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HLog(@"云手机推流界面 控制按钮中点%@",NSStringFromCGPoint(self.controlBtn.center));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// 1、悬浮球3s后 自动靠边隐藏
|
|
|
+- (void)extensionAdjustBtnFrameCheckAdjustTime {
|
|
|
+ self.adjustTime--;
|
|
|
+
|
|
|
+ if(self.adjustTime < 0){
|
|
|
+ self.adjustTime = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|