ソースを参照

VLCMovieViewController: Handle iPad and notchless devices correctly

Soomin Lee 5 年 前
コミット
bc91f3092a
1 ファイル変更24 行追加2 行削除
  1. 24 2
      Sources/VLCMovieViewController.m

+ 24 - 2
Sources/VLCMovieViewController.m

@@ -1286,7 +1286,10 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
 - (void) playbackServiceDidSwitchAspectRatio:(VLCAspectRatio)aspectRatio
 {
     _videoOptionsControlBar.isInFullScreen = aspectRatio == VLCAspectRatioFillToScreen;
-    [self adaptMovieViewToNotch];
+
+    if (@available(iOS 11, *)) {
+        [self adaptMovieViewToNotch];
+    }
 }
 
 - (void)displayMetadataForPlaybackService:(VLCPlaybackService *)playbackService
@@ -1755,8 +1758,27 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
     }
 }
 
-- (void)adaptMovieViewToNotch
+- (void)viewSafeAreaInsetsDidChange
 {
+    [super viewSafeAreaInsetsDidChange];
+
+    if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
+        return;
+    }
+
+    // safeAreaInsets can take some time to get set.
+    // Once updated, check if we need to update the constraints for notches
+    [self adaptMovieViewToNotch];
+}
+
+- (void)adaptMovieViewToNotch API_AVAILABLE(ios(11));
+{
+    // Ignore the constraint updates for iPads and notchless devices.
+    if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone
+        || (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && self.view.safeAreaInsets.bottom == 0)) {
+        return;
+    }
+
     // 30.0 represents the exact size of the notch
     CGFloat constant = _vpc.currentAspectRatio != VLCAspectRatioFillToScreen ? 30.0 : 0.0;