Unity3D使用storyboard作为launch screen之后遇到的问题

由于苹果要求2020 4.30以后,所有的启动页都得使用storyboard

如何设置storyboard为启动页:

https://forum.unity.com/threads/xcode-storyboard-option-for-splash-screens-launch-screens-in-ios-build.811131/

项目将启动页设置成Storyboard之后,ios13以下的系统,在“竖屏锁定”的情况下,启动页会闪一下竖屏的模式,再闪回横屏。

并且有的时候会闪一下游戏界面,然后又闪回启动页面。

这边研究了一下做了个投机取巧的方法:

1、横屏竖屏闪跳的问题:

修改Unity3D导出的UnityAppController.mm文件下的supportedInterfaceOrientationsForWindow方法:

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    // No rootViewController is set because we are switching from one view controller to another, all orientations should be enabled
    if ([window rootViewController] == nil)
        return UIInterfaceOrientationMaskAll;
    
    // NSLog(@"调用 supportedInterfaceOrientationsForWindow");
    // 由于我们项目在游戏过程中也会切换方向,所以设置了_onUnityStarted
    // 在startUnity方法调用之后设置为true
    if (_onUnityStarted)
    {
        // NSLog(@"unity 启动完成");
        return [[window rootViewController] supportedInterfaceOrientations] | _forceInterfaceOrientationMask;
    }
    else
    {
        // NSLog(@"unity 未开始");
        NSInteger defaultOrientation = ( UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
        return defaultOrientation | _forceInterfaceOrientationMask;
    }
}

 

2、有的时候会闪一下游戏界面,然后又闪回启动页面

修改修改Unity3D导出的UnityAppController.mm文件下的didFinishLaunchingWithOptions方法

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
	// 针对ios 13以下增加sleep(2)
    if (@available(iOS 13, *))
    {
        NSLog(@"is ios 13");
    }
    else
    {
        sleep(2);
    }
    ::printf("-> applicationDidFinishLaunching()\n");

    // send notfications
#if !PLATFORM_TVOS
    if (UILocalNotification* notification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey])
        UnitySendLocalNotification(notification);

    if ([UIDevice currentDevice].generatesDeviceOrientationNotifications == NO)
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
#endif

    UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]);

    [self selectRenderingAPI];
    [UnityRenderingView InitializeForAPI: self.renderingAPI];

    _window         = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
    _unityView      = [self createUnityView];

    [DisplayManager Initialize];
    _mainDisplay    = [DisplayManager Instance].mainDisplay;
    [_mainDisplay createWithWindow: _window andView: _unityView];

    [self createUI];
    [self preStartUnity];

    // if you wont use keyboard you may comment it out at save some memory
    [KeyboardDelegate Initialize];

#if !PLATFORM_TVOS && DISABLE_TOUCH_DELAYS
    for (UIGestureRecognizer *g in _window.gestureRecognizers)
    {
        g.delaysTouchesBegan = false;
    }
#endif

    return YES;
}

目前项目看起来比较正常

如果有更好的方法麻烦留言让我知道,谢谢~

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值