【发布时间】:2013-05-14 15:02:50
【问题描述】:
我正在使用Xcode 在MacOS 下编写一个简单的应用程序。我希望我的应用程序始终处于横向模式。所以我在项目属性中设置了横向。但是当我向我的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)];
并得到:
【问题讨论】:
-
请也发布您的代码
-
在界面生成器中检查界面方向
-
您是如何在视图控制器中为
iOS6+定义–shouldAutorotate方法,以及如何为<iOS6定义–shouldAutorotateToInterfaceOrientation:?
标签: ios ipad uikit uiinterfaceorientation