Reputation: 372
I'm writing a simple app under MacOS
using Xcode
. I want my app to be in landscape mode always. So I set landscape orientation in project properties. But when I add a button to my window.subview
, this button doesn't appear in landscape position.
I have only AppDelegate class. I've changed function: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
I've added:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor purpleColor];
[self.window makeKeyAndVisible];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setBackgroundColor:[UIColor whiteColor]];
[button setFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width/2 - 50, [[UIScreen mainScreen] bounds].size.height/2,
100, 100)];
[button setTitle:@"Button" forState:UIControlStateNormal];
[self.window addSubview:button];
Update: I added [self.window setTransform:CGAffineTransformMakeRotation(-M_PI/2)];
and got:
Upvotes: 1
Views: 330
Reputation: 372
I've solved it like this:
create my own RootViewController (like in How to create root view controller)
then:
self.rootController = [[AppRootViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.rootController;
[self.window addSubview:self.rootController.view];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
....
[[[self.window rootViewController] view] addSubview:button];
Upvotes: 1
Reputation: 3592
You can add UISupportedInterfaceOrientations
property in YourProject-info.plist as follow, then it will only support landscape orientation.
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
but do not know what's the meaning with your two pictures
Upvotes: 0
Reputation: 2577
There are two mechanisms that control this.
You already know about the target properties. If this is all you change, this should take care of it.
There is also a lower level control, which you might have picked up from old template code. For each view controller, if you implement the method
shouldRotateToInterfaceOrientation:
That will override the setting for the target. I suspect the superclasses implementation just refers to the target setting.
Upvotes: 0
Reputation: 4089
Select your target project and make sure you have choose following landscape mode:
Upvotes: 4