iOS按需更改屏幕方向

时间:2012-05-15 09:43:46

标签: ios orientation landscape portrait

我在主屏幕上有一个UITableView的应用。我认为这种观点始终是横向的。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
     return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

如果用户选择一行,他将被带到UIPageViewController视图。第二个视图可以旋转为横向和纵向。问题是当我在UIPageViewController上处于纵向模式并按下返回按钮时,应该始终处于横向模式的第一个视图现在是纵向的。旋转后,它进入风景并停留在那里。

我想知道是否有办法让我的主屏幕在我回到它时自动进入风景。

6 个答案:

答案 0 :(得分:2)

尝试以下

  1. 在横向模式下的界面构建器中,在app中创建主屏幕视图。
  2. 在界面类中创建uiview oultlet并将其连接到上面的视图                IBOutlet UIVIew *myView;
  3. 然后在viewDidLoad方法中设置此项                    self.view = self.myView;

答案 1 :(得分:1)

如果您想以特定方向制作屏幕,则可以创建CustomNavigation控制器,然后将其呈现在您的应用中。您只需返回supportedInterfaceOrientations。如果您需要更多详细信息和示例代码click here

答案 2 :(得分:0)

返回时手动拨打shouldAutorotateToInterfaceOrientation。你不能强迫“真正的”方向改变,这是操作系统的事情。

答案 3 :(得分:0)

view controller programming guide中所述,您可以使用备用横向界面,在从任何其他视图进入主屏幕之前,您可以检查方向并将相应的界面推到屏幕上

阅读此SO question并回答以便更好地了解在横向上启动应用程序。还要查看我指出的上述苹果编程指南。

答案 4 :(得分:0)

如果您使用UINavigationViewController方法(pushViewController:animated:popViewControllerAnimated:),则视图将继承先前视图的方向。

另一方面,如果您使用presentModalViewController:animated:dismissModalViewControllerAnimated:方法,一切都很完美。希望这有帮助!

答案 5 :(得分:0)

使用此选项,将UIInterfaceOrientationLandscapeLeft更改为所需的方向类型,如UIDeviceOrientationPortrait,UIDeviceOrientationLandscapeLeft等。

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
相关问题