-
Notifications
You must be signed in to change notification settings - Fork 481
点击旋转卡死或者旋转出现异常?
changsanjiang edited this page Sep 26, 2020
·
16 revisions
按照如下步骤, 配置好旋转即可:
-
step 1:
-
step 2:
@implementation AppDelegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
@end
/// swift
/// class AppDelegate: UIResponder, UIApplicationDelegate {
/// func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> /// UIInterfaceOrientationMask {
/// return .all
/// }
/// }
- step 3: 创建个 UIViewController 的分类, 将以下内容赋值到 .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