UnityPortraitOnlyViewController presentViewController出错

Unity写的游戏,转换成了xcode版本后,在presentViewController时有时候会出问题

Unity原来的控制器是UnityPortraitOnlyViewController 简称A

要展示的控制器,简称B

理论上 A执行了presentViewController:animated:completion:方法后,会展示B

但是很多时候B都是展示在了A的下面,用户看不到B

由于B是sdk内部的一个控制器,研究半天发现了原因

B的一个属性modalPresentationStyle设置为了UIModalPresentationOverCurrentContext导致的这个问题

后台将B的modalPresentationStyle 修改为UIModalPresentationFullScreen,就能正常展示了

用的方法是给UIViewController加了个Category

贴一下.m中的代码吧

#import "UIViewController+ZXC"

#import <UIKit/UIKit.h>

#include  <objc/runtime.h>

@implementation UIViewController (ZXC)

+ (void)load{

    SEL originalSelector =@selector(presentViewController:animated:completion:);

    SEL swizzledSelector =@selector(presentViewController11:animated:completion:);

    Method originalMethod = class_getInstanceMethod([selfclass], originalSelector);

    Method swizzledMethod = class_getInstanceMethod([selfclass], swizzledSelector);

    if(originalMethod && swizzledMethod) {

        method_exchangeImplementations(originalMethod, swizzledMethod);

    }

}

-(void)presentViewController11:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void(^)(void))completion{

    if([@"UnityPortraitOnlyViewController" isEqualToString:NSStringFromClass([self class])]) {

        if(viewControllerToPresent.modalPresentationStyle == UIModalPresentationOverCurrentContext) {                       viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen;

        }

    }

    [self presentViewController11:viewControllerToPresent animated:flag completion:completion];

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容