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:
–shouldAutorotate
method foriOS6+
, and how did you define the–shouldAutorotateToInterfaceOrientation:
for<iOS6
in your view controller? – holex