首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode -强制在Landscape中加载启动屏幕

Xcode -强制在Landscape中加载启动屏幕
EN

Stack Overflow用户
提问于 2015-09-04 10:44:12
回答 2查看 969关注 0票数 2

启动屏幕当前默认为设备的当前方向。我已经尝试通过编程来设置它,但它仍然不起作用。

代码语言:javascript
复制
override func viewDidLoad() {
    super.viewDidLoad()
    
    if UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait || UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown || UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown {
        UIDevice.currentDevice().setValue(UIInterfaceOrientation.LandscapeLeft.rawValue, forKey: "orientation")
    }
}

EN

回答 2

Stack Overflow用户

发布于 2015-09-04 10:47:03

您可以在目标的常规设置中设置Device Orientation

参考:http://www.raywenderlich.com/63229/make-game-like-mega-jump-spritekit-part-12

票数 0
EN

Stack Overflow用户

发布于 2017-09-19 15:42:22

最后,我想出了一个解决方案。启动屏幕是在应用程序运行之前生成的,所以这里有一个技巧。

在你的项目的常规设置中,只勾选左右景观,这样它就只会生成景观开机画面。并按如下方式混合NSBundle的infoDictionary方法:

代码语言:javascript
复制
@interface NSBundle (Hook)
@end

@implementation NSBundle (Hook)

+ (void)load {
    [NSBundle jr_swizzleMethod:@selector(infoDictionary)
                    withMethod:@selector(hook_infoDictionary)
                         error:NULL];
}

- (NSDictionary<NSString *, id> *)hook_infoDictionary
{
    NSMutableDictionary <NSString *, id> *dict = [[self hook_infoDictionary] mutableCopy];
    dict[@"UISupportedInterfaceOrientations"] = @[@"UIInterfaceOrientationPortrait",
                                                  @"UIInterfaceOrientationLandscapeLeft",
                                                  @"UIInterfaceOrientationLandscapeRight",
                                                  @"UIInterfaceOrientationPortraitUpsideDown",
                                                  ];
    return [dict copy];
}

@end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32389284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档