仅横向使用多个笔尖的iPhone应用程序

pgb*_*pgb 8 iphone landscape

我正在开发一个有几个笔尖的iPhone应用程序,应该只是风景.

应用程序设置为通过Info.plist文件以横向模式启动.

我有两个视图控制器: FirstViewControllerSecondViewController.

对于其中的每一个,我都有一个nib文件,其中视图是横向的.两个视图控制器都MainView作为插件添加到我的nib中,并且它们的视图被懒惰地初始化.

加载应用程序时,第一个视图按预期显示在横向中.但是,当我切换到第二个视图时,设备(或模拟器)保持横向,但视图旋转,就好像设备处于纵向模式,制动我的界面.

在这两个UIViewController类中,我有以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)

并切换视图,在我的app委托中我正在做:

[viewController.view removeFromSuperview];
[window addSubview:secondViewController.view];
Run Code Online (Sandbox Code Playgroud)

视图控制器连接的两个出口位置viewControllersecondViewController位置.

这是第二个视图在IB中的显示方式: alt text http://img27.imageshack.us/img27/4898/picture1ni.png

这就是它在模拟器中的样子: alt text http://img402.imageshack.us/img402/4866/picture2wt.png

为什么第二个视图在横向显示但是界面旋转了?

我不想处理转换属性,因为这似乎有点过分.

pix*_*x0r 3

我给这个问题加了星标,希望有人能给你一个有见地的回应,我会学到一些东西..遗憾的是,我担心你可能需要使用转换才能使其正常工作。这是我最近用来解决问题的代码:

- (void)forceLandscapeForView:(UIView *)theView {
  theView.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
  theView.bounds = CGRectMake(0, 0, 480, 320);
  theView.center = CGPointMake(160, 240);
  [theView setNeedsLayout];
  [theView setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)

然后,当您添加新视图时,检查当前方向,并在必要时强制旋转:

if (!UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
  [self forceLandscapeForView:_activeViewController.view];
}
Run Code Online (Sandbox Code Playgroud)

当然,您需要 shouldAutorotateToInterfaceOrientation在每个视图控制器中做出适当的响应:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Run Code Online (Sandbox Code Playgroud)

如果这不是必需的,我很想听听替代解决方案。我还注意到此设置有一个警告:如果您在视图之间进行转换,并且在该转换期间旋转手机,则视图方向可能会翻转或“卡在”错误的横向方向上,例如当您在视图之间导航时,需要将手机翻转(横向向右与横向向左)。