【问题标题】:UIViewController auto rotate not workingUIViewController 自动旋转不起作用
【发布时间】:2011-11-08 16:28:55
【问题描述】:

我在这个主题上找到了很多,但我就是想不通。任何帮助将不胜感激!

我有一个使用 UITabBarController 设置的应用程序。在其中一个选项卡中,我展示了一个 UITableView,它使用 UINavigationController 来允许层次结构。当方向改变时,所有表格都可以正常旋转,直到我到达层次结构中的最终视图。

最终的视图不是 UITableView,只是一个基本的UIView。但我无法让这个页面旋转成功!我已经根据所需的绝对基础重新制作了视图,但它仍然不想工作!代码如下,但它目前几乎是一个标准模板,现在没有任何内容。

另外,我没有使用 InterfaceBuilder,并且 shouldAutorotateToInterfaceOrientation 在所有视图上。这是我唯一遇到的问题。

SomeView.h

#import <UIKit/UIKit.h>
@interface SomeView : UIViewController
{
    NSString *someID;
    NSString *someName;
}
@property(nonatomic,retain) NSString *someID;
@property(nonatomic,retain) NSString *someName;
@end

SomeView.m

#import "SomeView.h"
#import "AppDelegate.h"
@implementation SomeView
@synthesize someID, someName;

-(void)loadView
{
}

-(void)viewDidLoad
{
    [super viewDidLoad];
}

-(void)viewDidUnload
{
    [super viewDidUnload];
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return YES;
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willAnimateRotationToInterfaceOrientation");
}

-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)dealloc
{
    [super dealloc];
}
@end

2011 年 11 月 10 日更新

我仍然遇到这个问题,但是查看文档和位似乎是我的问题 (http://developer.apple.com/library/ios/#qa/qa1688/_index.html)

视图控制器的 UIView 属性嵌入在 UIWindow 中,但旁边还有一个额外的视图控制器。

您可能会发现 shouldAutorotateToInterfaceOrientation 在启动时为给定视图控制器调用一次,但在设备旋转时不再调用。因为视图控制器与它们管理的视图紧密绑定,所以它们也是用于处理事件的响应者链的一部分。视图控制器本身是 UIResponder 类的后代,并被插入到托管视图与其父视图之间的响应者链中。因此,通常的做法是在您的应用程序中拥有一个主视图控制器作为响应者链的一部分。您通常会向您的 UIWindow 添加一个主视图控制器,例如 UINavigationController、UITabBarController 或通用 UIViewController。例如,这是通过调用:

[myWindow addSubview:primaryViewController.view];

如果您通过以下方式将其他视图控制器的 UIView 属性添加到 UIWindow(与主视图控制器处于同一级别):

[myWindow addSubview:anotherController.view];

这个额外的视图控制器不会接收旋转事件并且永远不会旋转。只有添加到 UIWindow 的第一个视图控制器会旋转。

【问题讨论】:

  • 是 SomeView 分配给标签栏中的一个标签,还是通过导航控制器从其他标签之一向下钻取导航到?
  • 这个 UIView 和另一个工作的 UIView 之间肯定有区别。也许一个简单的diff 会有所帮助。
  • @PaulTiarks tabbar 是根,someview 是通过在导航控制器中的 tableviews 下钻取的。
  • @ott 这是唯一的UIView,其余都是UITableView。

标签: iphone objective-c uiviewcontroller autorotate


【解决方案1】:

我的 UITabBarController 停止自动旋转,当我使用 tableViewController 添加一个新的 navigationController 并且没有注意到我的自定义导航控制器的 shouldAutorotateToInterfaceOrientation 仅针对一个方向返回 YES 时。解决办法是检查TabBarController里面每个Controller的shouldAutorotateToInterfaceOrientation函数。

可能会对某人有所帮助。

【讨论】:

    【解决方案2】:

    我已经想通了... 我正在查看将 UIViewController 推入堆栈的代码,但我还没有完全启动 UIViewController。

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多