我正在MacOS
using下编写一个简单的应用程序Xcode
。我希望我的应用程序始终处于横向模式。所以我在项目属性中设置了横向。但是当我在我的 中添加一个按钮时window.subview
,这个按钮不会出现在横向位置。
我只有 AppDelegate 类。我改变了函数:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
我已经添加:
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];
更新:我添加了 [self.window setTransform:CGAffineTransformMakeRotation(-M_PI/2)];
并得到: