ios - MPVolumeView 路由列表支持所有方向并忽略底层 View Controller

标签 ios orientation screen-rotation mpvolumeview

这似乎是操作系统错误,但仍然需要解决方法。

针对 iOS 8 或 9,使用基于 View Controller 的方向,MPVolumeView 的路由列表将始终旋转,即使其父 View Controller 仅支持单一方向也是如此。

这可能会导致系统进入不正确的方向状态,即 View Controller 以纵向显示,但状态栏(和控制中心)是横向的。

已创建一个演示错误的测试项目:https://github.com/NextFaze/MPVolumeViewTest

最佳答案

使用 swizzling 的 hacky 解决方案:

#import "UIViewController+RoutingSheet.h"
#import <objc/runtime.h>

@implementation UIViewController (RoutingSheet)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        SEL originalSelector = @selector(shouldAutorotate);
        SEL swizzledSelector = @selector(shouldAutoRotateOverrideRoutingSheet);
        Method originalMethod = class_getInstanceMethod(self, originalSelector);
        Method extendedMethod = class_getInstanceMethod(self, swizzledSelector);
        method_exchangeImplementations(originalMethod, extendedMethod);
    });
}

- (UIWindow *)currentWindow {
    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
        if (window.rootViewController == self)
            return window;
    }
    return nil;
}

- (BOOL)shouldAutoRotateOverrideRoutingSheet {
    UIWindow *window = [self currentWindow];
    if (window != nil) {
        NSString *className = NSStringFromClass(window.class);
        if ([className containsString:@"MPAVRoutingSheetSecureWindow"]) {
            return NO;
        }
    }
    return [self shouldAutoRotateOverrideRoutingSheet];
}

@end

关于ios - MPVolumeView 路由列表支持所有方向并忽略底层 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34347328/

相关文章:

ios - 使用 OpenGL 的神秘应用程序崩溃

iphone - 如何将我的应用程序限制为横向模式?

ios - 方向改变后放置方法的理想位置

cocoa - iOS 7 : Restrict device current orientation when modal view controller is presented

android - 多个DatePicker,屏幕旋转时强制关闭

android - iOS 会破坏旋转 View 吗?

android - 应该使用什么作为 url_launcher 中的 url 来使 flutter 应用程序打开设备上的内置摄像头?

ios - 单个容器 View 中的多个 subview Controller

javascript - zIndex 在 IOS 的 react-native 中无法正常工作

ios - ImageMagick 重新定向 iOS 照片