Skip to content

Commit

Permalink
Add interface orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
renzifeng committed Sep 26, 2022
1 parent f490839 commit 24b615d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,11 @@ - (void)viewDidLoad {
self.player.controlView = self.controlView;
self.player.orientationObserver.supportInterfaceOrientation = ZFInterfaceOrientationMaskLandscape;

UIInterfaceOrientation rotationOrientation = UIInterfaceOrientationLandscapeRight;
UIInterfaceOrientation currentOrientation = [self getCurrentOrientation];
if (UIInterfaceOrientationIsLandscape(currentOrientation)) {
rotationOrientation = currentOrientation;
}
/// 根据设备方向转屏
[self.player rotateToOrientation:rotationOrientation animated:NO completion:nil];
/// 设置转屏方向
[self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:NO completion:nil];
playerManager.assetURL = [NSURL URLWithString:@"https://www.apple.com/105/media/us/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-tpl-cc-us-20170912_1280x720h.mp4"];
}


- (UIInterfaceOrientation)getCurrentOrientation {
if (@available(iOS 16.0, *)) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160000
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *scene = [array firstObject];
return scene.interfaceOrientation;
#endif
} else {
return (UIInterfaceOrientation)[UIDevice currentDevice].orientation;
}
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
Expand Down
4 changes: 4 additions & 0 deletions ZFPlayer/Classes/Core/ZFOrientationObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ typedef NS_OPTIONS(NSUInteger, ZFDisablePortraitGestureTypes) {
/// default is ZFDisablePortraitGestureTypesAll.
@property (nonatomic, assign) ZFDisablePortraitGestureTypes disablePortraitGestureTypes;

/// The current orientation of the player.
/// Default is UIInterfaceOrientationPortrait.
@property (nonatomic, readonly) UIInterfaceOrientation currentOrientation;

/// Whether allow the video orientation rotate.
/// default is YES.
@property (nonatomic, assign) BOOL allowOrientationRotation;
Expand Down
17 changes: 7 additions & 10 deletions ZFPlayer/Classes/Core/ZFOrientationObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,6 @@ - (void)handleDeviceOrientationChange {
[self.landscapeRotationManager handleDeviceOrientationChange];
}

- (UIInterfaceOrientation)getCurrentOrientation {
if (@available(iOS 16.0, *)) {
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *scene = [array firstObject];
return scene.interfaceOrientation;
} else {
return (UIInterfaceOrientation)[UIDevice currentDevice].orientation;
}
}

#pragma mark - public

- (void)rotateToOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated {
Expand Down Expand Up @@ -264,6 +254,13 @@ - (UIView *)fullScreenContainerView {
return nil;
}

- (UIInterfaceOrientation)currentOrientation {
if (self.fullScreenMode == ZFFullScreenModeLandscape) {
return self.landscapeRotationManager.currentOrientation;
}
return [self.landscapeRotationManager getCurrentOrientation];
}

#pragma mark - setter

- (void)setLockedScreen:(BOOL)lockedScreen {
Expand Down

0 comments on commit 24b615d

Please sign in to comment.