Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rotate the iOS simulator using code?

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.

like image 799
Just a coder Avatar asked Mar 26 '13 16:03

Just a coder


People also ask

How do I rotate iPhone simulator?

Option 1: Use the left/right arrow keys while holding down command. Option 2: Under the Hardware tab at the top, select "Rotate Left" or "Rotate Right". At the top was missing in every other answer for option 2.

How do you rotate in simulator?

Android Simulators can be rotated using the following hotkeys: Linux – Ctrl + F12. Mac – Fn + Left Ctrl + F12. Windows – Left Ctrl + F11 or Left Ctrl + FF12.

How do I force an app to rotate on iOS?

iOS Settings and (lack of) Apps To find the setting in iOS 11, you will need to swipe up from the bottom of the screen and open the Control Center. Locate the Rotation Lock icon that looks like a lock, with an arrow circling it in a clockwise direction.

How do I change iOS simulator?

Sometimes the iOS simulator doesn't respond to the open command. If it seems stuck on this prompt, you can open the iOS simulator manually ( open -a Simulator ) and then in the macOS toolbar, choose Hardware → Device, and select an iOS version and device that you'd like to open.


1 Answers

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

Target Settings

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

Edit:
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.

Edit:
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
like image 89
Lance Avatar answered Sep 21 '22 05:09

Lance