MPVolumeView Route List supports all orientations and ignores the main view controller

This seems to be an OS bug, but a workaround is still needed.

Oriented to iOS 8 or 9 with an orientation based on the view controller, the MPVolumeView route list will always rotate, even if its parent view controller supports only one orientation.

This can cause the system to go into an incorrect orientation state when the view controller is displayed in the portrait, but the status bar (and the control center) are landscape.

Created a test project showing an error: https://github.com/NextFaze/MPVolumeViewTest

+5
source share
1 answer

hacked solution using swizzling:

 #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 
+1
source

Source: https://habr.com/ru/post/1238586/


All Articles