如何使用代码旋转 iOS 模拟器? [英] How do I rotate the iOS simulator using code?

查看:27
本文介绍了如何使用代码旋转 iOS 模拟器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何旋转iOS模拟器(6.0及以上)?我已经搜索过,但没有找到任何相关信息.

Does anyone know how to rotate the iOS Simulator (6.0 and above)? I've searched but have found nothing on this.

我正在尝试通过代码(而不是手动)执行此操作,但如果可以通过脚本完成,则必须从代码中运行.这甚至可以做到吗?需要一些建议.

I am trying to do this through code (not manually), but if it can be done through a script, then it has to be run from code. Can this even be done? Some advice needed.

推荐答案

将支持的界面方向的条目添加到测试目标(或任何合适的目标),如下所示:

Add an entry for Supported interface orientations to the Tests target (or whatever target is appropriate) like this:

只要唯一的条目是横向条目,它就会以横向模式运行.

As long as the only entries are Landscape ones, it will run in Landscape mode.


如果我误解了您对测试的评论并且您没有运行单元测试,那么您可能不想继续更改主要目标的方向.在这种情况下,您可以复制主要目标并在那里更改方向.


If I misunderstood your comment about tests and you aren't running unit tests, you probably don't want to keep changing the orientation of your main target. In that case, you could duplicate your main target and make the orientation change there.


有一种未公开的方法可以在代码中强制旋转.虽然这适用于测试,但如果您在提交的应用中使用它,可能会导致您的应用被拒绝.


There is an undocumented method to force rotation in code. While this will work for tests, it could get your app rejected if you use it in a submitted app.

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight animated:YES];

只需在需要使用此方法的任何地方包含此类别.

Just include this category wherever you need to use this method.

@interface UIDevice (MethodsThatAppleWillHitMeWithTheBanStickForUsing)
    -(void)setOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated;
    -(void)setOrientation:(UIInterfaceOrientation)orientation;
@end

这篇关于如何使用代码旋转 iOS 模拟器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆