找回密码
 立即注册
查看: 410|回复: 0

UnityPortraitOnlyViewController presentViewController出错

[复制链接]
发表于 2022-4-20 17:43 | 显示全部楼层 |阅读模式
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
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-16 21:41 , Processed in 0.135546 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表