由于苹果要求2020 4.30以后,所有的启动页都得使用storyboard
如何设置storyboard为启动页:
项目将启动页设置成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;
}
目前项目看起来比较正常
如果有更好的方法麻烦留言让我知道,谢谢~