我已经尝试将以下代码添加到我的landscpae ipad应用程序中并且工作正常...但是在xcode6中知道它看起来是错误的(请参阅打印屏幕)
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
self.window.rootViewController = self.loginRegisterView;
CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57079633);
[self.window setTransform:rotate];
CGRect contentRect = CGRectMake(0, 0, 1024, 768);
self.window.bounds = contentRect;
[self.window makeKeyAndVisible];
当我启动应用时,会显示:https://imageshack.com/i/kqo1EBgAp
编辑:
现在,我不会手动旋转窗口...仅在常规选项卡中,如打印屏幕
https://imageshack.com/i/idzqoTZQp
这是xib文件
https://imageshack.com/i/ipB1cOpGp
以及它在设备上的显示方式
答案 0 :(得分:4)
当您在app委托中设置窗口时,问题似乎是调用的顺序。在分配makeKeyAndVisible
之前,您需要致电rootViewController
。以下作品:
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
self.window.rootViewController = self.myMainViewController;
但如果您将订单更改为:
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = self.myMainViewController;
[self.window makeKeyAndVisible];
您会遇到您遇到的行为。
答案 1 :(得分:0)
我在viewDidLoad
中添加了以下代码 - (void)viewDidLoad
{
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI/2);
[self.view setTransform:rotate];
[self.view setFrame:CGRectMake(0, 0, 768, 1024)];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
编辑:
如果加入
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions it works for all the views
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI/2);
[self.window setTransform:rotate];
[self.window setFrame:CGRectMake(0, 0, 768, 1024)];