-
Notifications
You must be signed in to change notification settings - Fork 479
点击旋转卡死或者旋转出现异常?
changsanjiang edited this page Aug 15, 2022
·
16 revisions
出现此种情况, 是因为未配置旋转, 请按照以下步骤进行配置:
- step 1:
In your project, select TARGETS
-> General
-> Deployment Info
-> Device Orientation
-> select only Portrait
- step 2:
#import "SJRotationManager.h"
@implementation AppDelegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [SJRotationManager supportedInterfaceOrientationsForWindow:window];
}
@end
/// swift
/// class AppDelegate: UIResponder, UIApplicationDelegate {
/// func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> /// UIInterfaceOrientationMask {
/// return SJRotationManager.supportedInterfaceOrientations(window)
/// }
/// }
- step 3: 创建一个
UIViewController+RotationControl
的分类, 将以下内容复制到UIViewController+RotationControl.m
中.
@implementation UIViewController (RotationControl)
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
@end
@implementation UITabBarController (RotationControl)
- (UIViewController *)sj_topViewController {
if ( self.selectedIndex == NSNotFound )
return self.viewControllers.firstObject;
return self.selectedViewController;
}
- (BOOL)shouldAutorotate {
return [[self sj_topViewController] shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return [[self sj_topViewController] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self sj_topViewController] preferredInterfaceOrientationForPresentation];
}
@end
@implementation UINavigationController (RotationControl)
- (BOOL)shouldAutorotate {
return self.topViewController.shouldAutorotate;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.topViewController.supportedInterfaceOrientations;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return self.topViewController.preferredInterfaceOrientationForPresentation;
}
- (nullable UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}
- (nullable UIViewController *)childViewControllerForStatusBarHidden {
return self.topViewController;
}
@end
- setup 4: iOS 13.0 之后, 需在自己的vc中实现
shouldAutorotate
, 并返回NO
.
@interface YourPlayerViewController ()
@property (nonatomic, strong) SJVideoPlayer *player;
@end
@implementation YourPlayerViewController
- (BOOL)shouldAutorotate {
return NO;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_player vc_viewDidAppear];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[_player vc_viewWillDisappear];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[_player vc_viewDidDisappear];
}
@end