Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

旋转控制没有效果 #715

Closed
ChengminZhang opened this issue Sep 24, 2019 · 2 comments
Closed

旋转控制没有效果 #715

ChengminZhang opened this issue Sep 24, 2019 · 2 comments
Labels

Comments

@ChengminZhang
Copy link

ChengminZhang commented Sep 24, 2019

Bug 表现

安装 QMUI 4.0.0-beta 后旋转出了问题。

QMUI-3.2.1版本我设置了BaseViewController->UIInterfaceOrientationMaskPortrait,某些页面支持UIInterfaceOrientationMaskAll,在3.2.1表现很好,4.0.0-beta版本后出现没有作用的情况。

猜测原因

4.0.0 版本 QMUITabBarViewController 通过supportedInterfaceOrientations设置可用的旋转方向,shouldAutorotate控制当前旋转方向。
3.2.1 版本 QMUITabBarViewController 通过supportedInterfaceOrientations控制旋转方向。

将 QMUITabBarViewController下的 supportedInterfaceOrientations 替换回 3.2.1版本的 supportedInterfaceOrientations写法不会出现该问题。

//QMUI 4.0.0-beta.
#pragma mark - 屏幕旋转

- (BOOL)shouldAutorotate {
    return self.presentedViewController ? [self.presentedViewController shouldAutorotate] : ([self.selectedViewController qmui_hasOverrideUIKitMethod:_cmd] ? [self.selectedViewController shouldAutorotate] : YES);
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    
    // fix UIAlertController:supportedInterfaceOrientations was invoked recursively!
    // crash in iOS 9 and show log in iOS 10 and later
    // https://github.com/Tencent/QMUI_iOS/issues/502
    // https://github.com/Tencent/QMUI_iOS/issues/632
    UIViewController *visibleViewController = self.presentedViewController;
    if (visibleViewController && [visibleViewController isKindOfClass:UIAlertController.class]) {
        visibleViewController = self.selectedViewController;
    }
    
    return [visibleViewController qmui_hasOverrideUIKitMethod:_cmd] ? [visibleViewController supportedInterfaceOrientations] : SupportedOrientationMask;
}
//QMUI 3.2.1
#pragma mark - 横竖屏
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    // QMUI 4.0.0 -beta 修改这段代码,回退代码可以避免问题。
    UIViewController *presentedViewController = self.presentedViewController;
    if (IOS_VERSION_NUMBER < 100000 && presentedViewController && [presentedViewController isKindOfClass:UIAlertController.class]) {
        presentedViewController = nil;
    }
    
    return presentedViewController ? [presentedViewController supportedInterfaceOrientations] : ([self.selectedViewController qmui_hasOverrideUIKitMethod:_cmd] ? [self.selectedViewController supportedInterfaceOrientations] : SupportedOrientationMask);
}

其他信息

  • 设备:iPhone 7
  • iOS 版本: [iOS 13]
  • Xcode 版本: [Xcode 11]
  • QMUI 版本: [4.0.0-beta]
@MoLice
Copy link
Collaborator

MoLice commented Sep 24, 2019

这是 4.0.0-beta 的 bug,新版本将会修复,在此之前可以按照下文替换正确的代码:

QMUITabBarViewController.m:

- (BOOL)shouldAutorotate {
    return self.presentedViewController ? [self.presentedViewController shouldAutorotate] : ([self.selectedViewController qmui_hasOverrideUIKitMethod:_cmd] ? [self.selectedViewController shouldAutorotate] : YES);
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    
    // fix UIAlertController:supportedInterfaceOrientations was invoked recursively!
    // crash in iOS 9 and show log in iOS 10 and later
    // https://github.com/Tencent/QMUI_iOS/issues/502
    // https://github.com/Tencent/QMUI_iOS/issues/632
    UIViewController *visibleViewController = self.presentedViewController;
    if (!visibleViewController || visibleViewController.isBeingDismissed || [visibleViewController isKindOfClass:UIAlertController.class]) {
        visibleViewController = self.selectedViewController;
    }
    
    if ([visibleViewController isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
        return visibleViewController.supportedInterfaceOrientations;
    }
    
    return [visibleViewController qmui_hasOverrideUIKitMethod:_cmd] ? [visibleViewController supportedInterfaceOrientations] : SupportedOrientationMask;
}

QMUINavigationController.m:

- (BOOL)shouldAutorotate {
    return [self.visibleViewController qmui_hasOverrideUIKitMethod:_cmd] ? [self.visibleViewController shouldAutorotate] : YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    // fix UIAlertController:supportedInterfaceOrientations was invoked recursively!
    // crash in iOS 9 and show log in iOS 10 and later
    // https://github.com/Tencent/QMUI_iOS/issues/502
    // https://github.com/Tencent/QMUI_iOS/issues/632
    UIViewController *visibleViewController = self.visibleViewController;
    if (!visibleViewController || visibleViewController.isBeingDismissed || [visibleViewController isKindOfClass:UIAlertController.class]) {
        visibleViewController = self.topViewController;
    }
    return [visibleViewController qmui_hasOverrideUIKitMethod:_cmd] ? [visibleViewController supportedInterfaceOrientations] : SupportedOrientationMask;
}

@MoLice MoLice added the bug label Sep 24, 2019
@MoLice
Copy link
Collaborator

MoLice commented Sep 27, 2019

已发布 4.0.0 版本修复该问题。

@MoLice MoLice closed this as completed Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants