UIDeviceOrientationDidChangeNotification没有解雇? [英] UIDeviceOrientationDidChangeNotification not firing?

查看:96
本文介绍了UIDeviceOrientationDidChangeNotification没有解雇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根本无法触发 UIDeviceOrientationDidChangeNotification

我有我的AppDelegate,在这里我添加了一个 PolyOrientationViewController ,它有 UInavigationController ,可以推送 VerticalNavigationController 和一个 Horizo​​ntalViewController 取决于iPad的方向。

I have my AppDelegate, here I add a PolyOrientationViewController, which has a UInavigationController that can push a VerticalNavigationController and a HorizontalViewController depending on the orientation of the iPad.

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

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

    return YES;
}

Poly,Vertical和Horizo​​ntal viewController实现:

Poly, Vertical and Horizontal viewController implements:

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

PolyVC,它是最顶级的ViewController,它有以下方法:

PolyVC, which is the top most ViewController, it has these methods:

- (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 ,我认为。

Upon the instantiation of the PolyVC, the didRotate: method is called, from here on it simply stops generating the UIDeviceOrientationDidChangeNotification, I think.

我在中有一个断点didRotate:方法,我已经将应用程序加载到iPad上以确保它不是模拟器的东西,我已经制作了一个新的xcode splitViewController项目,测试了旋转工作,删除了代码并粘贴了我自己的,我已经检查了orientation-lock按钮,我已经尝试实现 - (BOOL)ShouldAutoRotate ... 我既没有被调用,我检查了info.plist指定了应用程序支持所有的方向,我已经尝试从我的一个工作示例中复制粘贴每一段通知代码d淘汰拼写错误。

I have a breakpoint in the didRotate: method, I have loaded the app onto an iPad to make sure it was not a simulator thing, I have made a new xcode splitViewController project, tested the rotation worked, deleted the code and pasted my own, I have checked the orientation-lock button, I have tried implementing the -(BOOL) ShouldAutoRotate… I is neither called, I checked that the info.plist specifies that the app supports all the orientations, I have tried copy pasting every piece of notification code from a working example I found to weed out typos.

我完全在我的智慧结束这里:)有什么我可以做的,一些实现UIViewController的方法,不使用IB,在ViewControllers中嵌套ViewControllers(PolyViewController拥有拥有Vertical和Horizo​​ntalViewController的UINavigationController)或任何会让应用完全忽略interfaceOrientation通知的东西?

I am completely at my wits end here:) Is there something I could have done, some way of implementing a UIViewController, not using IB, nesting ViewControllers inside ViewControllers (PolyViewController owns UINavigationController that owns Vertical and HorizontalViewController) or anything that will make the app completely ignore interfaceOrientation notifications?

我希望有人可以指出我的错误: )
提前谢谢。

I hope someone can point out my mistake :) Thank you in advance.

推荐答案

从文档中摘录,试试它是否有帮助:

Extracted from the documentation, try if it helps:


您可以使用orientation属性获取当前方向,也可以通过注册UIDeviceOrientationDidChangeNotification通知来接收更改通知。在使用这些技术之一获取方向数据之前,必须使用beginGeneratingDeviceOrientationNotifications方法启用数据传递。当您不再需要跟踪设备方向时,请调用endGeneratingDeviceOrientationNotifications方法以禁用通知的传递。

You get the current orientation using the orientation property or receive change notifications by registering for the UIDeviceOrientationDidChangeNotification notification. Before using either of these techniques to get orientation data, you must enable data delivery using the beginGeneratingDeviceOrientationNotifications method. When you no longer need to track the device orientation, call the endGeneratingDeviceOrientationNotifications method to disable the delivery of notifications.

这篇关于UIDeviceOrientationDidChangeNotification没有解雇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆