From 5bc255efe4b83702db368b7af3945e9a8368bfce Mon Sep 17 00:00:00 2001
From: Davin <591807572@qq.com>
Date: 星期二, 13 六月 2023 20:19:09 +0800
Subject: [PATCH] faeture 摄像头放大功能

---
 EZSDK/EZSDK/EZ/UIViewControllers/EZLivePlayViewController.m |   97 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/EZSDK/EZSDK/EZ/UIViewControllers/EZLivePlayViewController.m b/EZSDK/EZSDK/EZ/UIViewControllers/EZLivePlayViewController.m
index 7835c22..fdd73f4 100644
--- a/EZSDK/EZSDK/EZ/UIViewControllers/EZLivePlayViewController.m
+++ b/EZSDK/EZSDK/EZ/UIViewControllers/EZLivePlayViewController.m
@@ -32,6 +32,7 @@
 {
     NSOperation *op;
     BOOL _isPressed;
+    BOOL _landscape;    // 鏄惁鏃嬭浆
 }
 
 @property (nonatomic) BOOL isOpenSound;
@@ -89,7 +90,7 @@
 @property (weak, nonatomic) IBOutlet UILabel *streamTypeLabel;
 @property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
 @property (weak, nonatomic) IBOutlet UILabel *zoomSizeLabel;
-
+@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollViewWHRatio; // 婊氬姩瑙嗗浘瀹介珮姣�
 @property (nonatomic, strong) HDLEZButton *unlockButton;//寮�閿佹寜閽�
 
 @property (nonatomic, copy) NSString *streamToken;
@@ -528,9 +529,22 @@
     }
 }
 
-- (UIInterfaceOrientationMask)supportedInterfaceOrientations
-{
-    return UIInterfaceOrientationMaskAllButUpsideDown;
+//- (UIInterfaceOrientationMask)supportedInterfaceOrientations
+//{
+//    return UIInterfaceOrientationMaskAllButUpsideDown;
+//}
+- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
+    if (@available(iOS 16.0, *)) {
+        if (_landscape) {
+            //妯睆
+            return UIInterfaceOrientationMaskLandscape;
+        } else {
+            //绔栧睆
+            return UIInterfaceOrientationMaskPortrait;
+        }
+    } else {
+        return UIInterfaceOrientationMaskAllButUpsideDown;
+    }
 }
 
 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
@@ -542,6 +556,17 @@
     self.bottomView.hidden = NO;
     self.largeTitleLabel.hidden = YES;
     self.localRecrodContraint.constant = 10;
+    
+    [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [self.toolBar setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [NSLayoutConstraint deactivateConstraints:@[self.scrollViewWHRatio]];
+    self.scrollViewWHRatio = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeHeight multiplier:16/9. constant:0];
+    [NSLayoutConstraint activateConstraints:@[self.scrollViewWHRatio]];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [self.scrollView layoutIfNeeded];
+        [self.toolBar layoutIfNeeded];
+    });
+    
     if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
     {
@@ -551,6 +576,20 @@
         self.largeTitleLabel.hidden = NO;
         self.largeBackButton.hidden = NO;
         self.bottomView.hidden = YES;
+        
+        CGFloat tureScreenW = HDLEZ_APP_SCREEN_WIDTH > HDLEZ_APP_SCREEN_HEIGHT ? HDLEZ_APP_SCREEN_HEIGHT : HDLEZ_APP_SCREEN_WIDTH;
+        CGFloat tureScreenH = HDLEZ_APP_SCREEN_WIDTH < HDLEZ_APP_SCREEN_HEIGHT ? HDLEZ_APP_SCREEN_HEIGHT : HDLEZ_APP_SCREEN_WIDTH;
+
+        
+        [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [self.toolBar setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [NSLayoutConstraint deactivateConstraints:@[self.scrollViewWHRatio]];
+        self.scrollViewWHRatio = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeHeight multiplier:tureScreenH/tureScreenW constant:0];
+        [NSLayoutConstraint activateConstraints:@[self.scrollViewWHRatio]];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self.scrollView layoutIfNeeded];
+            [self.toolBar layoutIfNeeded];
+        });
     }
 }
 
@@ -819,14 +858,56 @@
 
 - (IBAction)large:(id)sender
 {
-    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
-    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
+    NSLog(@"######杩涘叆妯睆锛�");
+    if (@available(iOS 16.0, *)) {
+        _landscape = YES;
+        if (self.navigationController) {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
+            });
+        } else {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self setNeedsUpdateOfSupportedInterfaceOrientations];
+            });
+        }
+        NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
+        UIWindowScene *ws = (UIWindowScene *)array.firstObject;
+        UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
+        geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskLandscape;
+        [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {
+            NSLog(@"iOS 16 Error: %@",error);
+        }];
+    } else {
+        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
+        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
+    }
 }
 
 - (IBAction)largeBack:(id)sender
 {
-    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
-    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
+    NSLog(@"######鏀跺洖妯睆锛�");
+    if (@available(iOS 16.0, *)) {
+        _landscape = NO;
+        if (self.navigationController) {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
+            });
+        } else {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self setNeedsUpdateOfSupportedInterfaceOrientations];
+            });
+        }
+        NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
+        UIWindowScene *ws = (UIWindowScene *)array.firstObject;
+        UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
+        geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskPortrait;
+        [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {
+            NSLog(@"iOS 16 Error: %@",error);
+        }];
+    } else {
+        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
+        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
+    }
 }
 
 - (IBAction)capture:(id)sender

--
Gitblit v1.8.0