renzifeng/ZFPlayer

在横屏界面,进行横竖屏变换的时候,横屏返回的时候,返回到上一层界面还是横屏, 没有恢复竖屏界面

k214k opened this issue · 3 comments

k214k commented

在ios16,从上层横屏界面的自定义控制层,到播放界面,进行横竖屏变换的时候,横屏返回的时候,返回到上一层界面还是横屏, 没有恢复竖屏界面,请问是什么原因产生的?在横屏界面播放的时候,横屏界面上的图标显示不正常。我在库中这个函数下进行修改还是无法达到预期效果。
代码如下:

  • (void)interfaceOrientation:(UIInterfaceOrientation)orientation {

    @Try {
    // ios16使用新的api
    if (@available(iOS 16.0, *)) {
    UIInterfaceOrientationMask oriMask = UIInterfaceOrientationMaskPortrait;
    if (orientation != UIDeviceOrientationPortrait && orientation != UIDeviceOrientationUnknown) {
    oriMask = UIInterfaceOrientationMaskLandscapeRight;
    }
    // 防止appDelegate supportedInterfaceOrientationsForWindow方法不调用
    UINavigationController nav = [self getCurrentVC].navigationController;//[TYToolsUtil topViewController].navigationController;
    SEL selUpdateSupportedMethod = NSSelectorFromString(@"setNeedsUpdateOfSupportedInterfaceOrientations");
    if ([nav respondsToSelector:selUpdateSupportedMethod]) {
    (((void (
    )(id, SEL))[nav methodForSelector:selUpdateSupportedMethod])(nav, selUpdateSupportedMethod));
    }

             NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
             UIWindowScene *ws = (UIWindowScene *)array.firstObject;
             Class GeometryPreferences = NSClassFromString(@"UIWindowSceneGeometryPreferencesIOS");
             id geometryPreferences = [[GeometryPreferences alloc] init];
             [geometryPreferences setValue:@(oriMask) forKey:@"interfaceOrientations"];
             SEL selGeometryUpdateMethod = NSSelectorFromString(@"requestGeometryUpdateWithPreferences:errorHandler:");
             void (^ErrorBlock)(NSError *error) = ^(NSError *error){
                   NSLog(@"iOS 16 转屏Error: %@",error);
             };
             if ([ws respondsToSelector:selGeometryUpdateMethod]) {
                 (((void (*)(id, SEL,id,id))[ws methodForSelector:selGeometryUpdateMethod])(ws, selGeometryUpdateMethod,geometryPreferences,ErrorBlock));
             }
    
         } else {
    
             if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
                 SEL selector = NSSelectorFromString(@"setOrientation:");
                 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
                 [invocation setSelector:selector];
                 [invocation setTarget:[UIDevice currentDevice]];
                 UIInterfaceOrientation val = orientation;
                 [invocation setArgument:&val atIndex:2];
                 [invocation invoke];
             }
         }
    
     } @catch (NSException *exception) {
    
     } @finally {
    
     }
    

请问你是怎么改的呢?iOS16 shouldAutorotate没用了,你是把原来ZFLandScapeViewController里的shouldAutorotate的逻辑移到哪里去了呢

同问,辛苦解答一下,非常感谢

fix 4.1.0