【问题标题】:iPhone navigation bar rotation issue when coming back from background从后台返回时 iPhone 导航栏旋转问题
【发布时间】:2011-05-05 05:10:04
【问题描述】:

好吧,经过数周的头痛,我已经放弃并决定求助于在线专家资源!

基本上,我试图让我的 iphone 应用程序以强制横向模式(准确地说,对于图形)查看,以便在以纵向为主的导航栏应用程序中仅使用 1 个视图控制器。

我让一切正常工作,除了当我将应用程序置于后台并返回时,应用程序返回时导航栏移动到它通常位于纵向模式但旋转 90' 的位置,而其他所有人都喜欢状态栏,主视图仍处于横向模式。

之后我尝试手动更正导航栏方向,但 cocoa 似乎忽略了这段代码。当应用程序从后台模式返回时,几乎就像 self.view.transform 不起作用一样。有什么建议吗?

LandscapeViewController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}

-(void)viewWillAppear:(BOOL)animated {
    self.view.transform = CGAffineTransformMakeRotation((M_PI * (90) / 180.0));
    self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
}  

这张图片让你明白我的意思

http://i.stack.imgur.com/Qx1Si.png

【问题讨论】:

  • 我不知道它是否会有所帮助,但您应该了解导航控制器视图不属于您的视图控制器视图。它是 UINavigationController 实例的视图。所以当你调用 self.view.transform... 和 self.view.bounds... 它不会影响导航栏。

标签: objective-c cocoa-touch ios4 background orientation


【解决方案1】:

你试过了吗?

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

【讨论】:

  • 是的,我已经尝试过了,但仍然没有修复。看起来像这里的图片 - i.imgur.com/Qx1Si.png
【解决方案2】:

您不应该总是从 shouldAutorotateToInterfaceOrientation: 返回 NO,而是为您支持的方向返回 YES。然后 iOS 会处理其余部分。

【讨论】:

  • 我已经做到了。还要在 shouldAutorotate... 上放置一个断点,以确认从后台返回时正在调用它。但是,它仍然没有解决我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多