2010-09-29 142 views
2

我根本无法让UIDeviceOrientationDidChangeNotification着火。UIDeviceOrientationDidChangeNotification不会触发?

我有我的AppDelegate,在这里我想补充一个PolyOrientationViewController,其中有一个UInavigationController可以推VerticalNavigationControllerHorizontalViewController根据对iPad的方向。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    ISPolyOrientationTableViewController *pvc = [[ISPolyOrientationTableViewController alloc] init]; 
    [window addSubview:pvc.view]; 
    [pvc release]; 
    [window makeKeyAndVisible]; 

    return YES; 
} 

保利,垂直和水平的viewController实现:

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

PolyVC,这是最上面的视图控制器,它有以下方法:

- (void)viewDidLoad { 

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) 
               name:UIDeviceOrientationDidChangeNotification 
               object:nil]; 

    [super viewDidLoad]; 
} 

它具有相关功能:

- (void)didRotate:(NSNotification *)notification { 
    //push the related controller 
} 

在PolyVC实例化后,调用didRotate:方法,从这里开始,它简单地停止生成UIDeviceOrientationDidChangeNotification,我想。

我在didRotate:方法中有一个断点,我已经将应用程序加载到iPad上以确保它不是模拟器的东西,我做了一个新的xcode splitViewController项目,测试了旋转工作,删除了代码并粘贴我已经检查了方向锁定按钮,我试过执行-(BOOL) ShouldAutoRotate…我没有被调用,我检查了info.plist指定该应用程序支持所有方向,我尝试了复制粘贴每一条通知代码我找到了一个工作实例来清除拼写错误。我有一些我可以做的,一些实现UIViewController,不使用IB,在ViewControllers中嵌套ViewControllers(PolyViewController拥有UINavigationController,拥有Vertical和Horizo​​ntalViewController)或任何其他的东西将使应用程序完全忽略interfaceOrientation通知?

我希望有人能指出我的错误:) 先谢谢您。

+0

找到这篇博客。这是非常有用的,简单和工作http://blog.sallarp.com/iphone-shouldautorotatetointerfaceorientation-breaking-changes/ – 2011-04-19 17:38:54

回答

7

Extracted from the documentation,尝试,如果它有助于:

你得到使用方向属性的当前方位或为UIDeviceOrientationDidChangeNotification通知注册接收更改通知。在使用这两种技术获取方向数据之前,您必须使用beginGeneratingDeviceOrientationNotifications方法启用数据传递。当您不再需要跟踪设备方向时,请调用endGeneratingDeviceOrientationNotifications方法来禁用通知的传递。

6

此症状(在初始化时会触发一次通知,然后停止)听起来像是因为您已停用了iPhone中的方向更改。无论如何,这就是我发生的事情。