【问题标题】:UIDeviceOrientationDidChangeNotification not firing?UIDevice OrientationDidChangeNotification 没有触发?
【发布时间】:2010-09-29 11:27:27
【问题描述】:

我根本无法触发UIDeviceOrientationDidChangeNotification

我有我的 AppDelegate,在这里我添加了一个PolyOrientationViewController,它有一个UInavigationController,可以根据 iPad 的方向推送一个VerticalNavigationController 和一个HorizontalViewController

- (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 实现:

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

PolyVC,也就是最顶层的ViewController,它有这些方法:

- (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 通知?

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

【问题讨论】:

标签: ipad


【解决方案1】:

Extracted from the documentation,如果有帮助就试试吧:

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

【讨论】:

    【解决方案2】:

    此症状(在初始化时触发一次然后停止)听起来像是因为您已停用 iPhone 中的方向更改。反正我就是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 2019-07-08
      • 2017-12-16
      • 2017-08-15
      • 2020-02-06
      • 2013-05-31
      • 2013-03-13
      相关资源
      最近更新 更多