From 24cb5f1e93b77b744ab702d6a75c6d6b94bbf359 Mon Sep 17 00:00:00 2001
From: Davin <591807572@qq.com>
Date: 星期二, 20 六月 2023 13:49:41 +0800
Subject: [PATCH] faeture 视频回放横屏适配

---
 EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m |   92 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m b/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m
index 0f12198..34cb569 100644
--- a/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m
+++ b/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m
@@ -31,6 +31,7 @@
 {
     BOOL _isOpenSound;
     BOOL _isPlaying;
+    BOOL _landscape;    // 鏄惁鏃嬭浆
     
     NSTimeInterval _playSeconds; //鎾斁绉掓暟
     NSTimeInterval _duringSeconds; //褰曞儚鏃堕暱
@@ -57,6 +58,7 @@
 @property (nonatomic, strong) HIKLoadView *loadingView;
 @property (nonatomic) BOOL isSelectedDevice;
 @property (nonatomic, weak) IBOutlet UIView *playerView;
+@property (weak, nonatomic) IBOutlet NSLayoutConstraint *playViewWHScale;
 @property (nonatomic, weak) IBOutlet UILabel *largeTitleLabel;
 @property (nonatomic, weak) IBOutlet UIDatePicker *datePicker;
 @property (nonatomic, weak) IBOutlet UITextField *dateTextField;
@@ -115,6 +117,7 @@
     self.isAutorotate = YES;
     self.largeTitleLabel.text = self.deviceInfo.deviceName;
     self.largeTitleLabel.hidden = YES;
+    _landscape = NO;
     
     if(!_records)
         _records = [NSMutableArray new];
@@ -227,7 +230,17 @@
 
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations
 {
-    return UIInterfaceOrientationMaskAllButUpsideDown;
+    if (@available(iOS 16.0, *)) {
+        if (_landscape) {
+            //妯睆
+            return UIInterfaceOrientationMaskLandscape;
+        } else {
+            //绔栧睆
+            return UIInterfaceOrientationMaskPortrait;
+        }
+    } else {
+        return UIInterfaceOrientationMaskAllButUpsideDown;
+    }
 }
 
 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
@@ -242,6 +255,13 @@
     self.largeButton.hidden = NO;
     self.voiceButton.hidden = NO;
     self.playButton.hidden = NO;
+    [self.playerView setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [NSLayoutConstraint deactivateConstraints:@[self.playViewWHScale]];
+    self.playViewWHScale = [NSLayoutConstraint constraintWithItem:self.playerView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.playerView attribute:NSLayoutAttributeHeight multiplier:16/9. constant:0];
+    [NSLayoutConstraint activateConstraints:@[self.playViewWHScale]];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [self.playerView layoutIfNeeded];
+    });
     if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
     {
@@ -254,6 +274,18 @@
         self.playbackList.hidden = YES;
         self.largeBackButton.hidden = NO;
         self.navigationController.navigationBarHidden = 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.playerView setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [NSLayoutConstraint deactivateConstraints:@[self.playViewWHScale]];
+        self.playViewWHScale = [NSLayoutConstraint constraintWithItem:self.playerView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.playerView attribute:NSLayoutAttributeHeight multiplier:tureScreenH/(tureScreenW) constant:0];
+        [NSLayoutConstraint activateConstraints:@[self.playViewWHScale]];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self.playerView layoutIfNeeded];
+        });
     }
 }
 
@@ -757,14 +789,60 @@
 
 - (IBAction)large:(id)sender
 {
-    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
-    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
+//    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
+//    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
+    if (_landscape == YES) {
+        [self largeBack:self.largeBackButton];
+        return;
+    }
+    _landscape = YES;
+    if (@available(iOS 16.0, *)) {
+        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"];
+    _landscape = NO;
+    if (@available(iOS 16.0, *)) {
+        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)voiceButtonClicked:(id)sender
@@ -1160,4 +1238,8 @@
     }
 }
 
+- (BOOL)prefersHomeIndicatorAutoHidden {
+    return YES;
+}
+
 @end

--
Gitblit v1.8.0