ainatipen 发表于 2022-4-20 17:43

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加了个

贴一下.m中的代码吧

#import "UIViewController+ZXC"

#import<UIKit/UIKit.h>

#include<objc/runtime.h>

@implementation UIViewController (ZXC)

+ (void)load{

SELoriginalSelector =@selector(presentViewController:animated:completion:);

SELswizzledSelector =@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 *)viewControllerToPresentanimated:(BOOL)flagcompletion:(void(^)(void))completion{

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

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

    }

}

[selfpresentViewController11:viewControllerToPresent animated:flag completion:completion];

}

@end
页: [1]
查看完整版本: UnityPortraitOnlyViewController presentViewController出错