iphone - 不会触发任何与方向相关的通知。为什么?

标签 iphone objective-c ios notifications nsnotificationcenter

我希望在设备方向发生变化时收到通知。我已经设置了一个应该接收通知的测试方法。我正在尝试几个不同的观察者来实现这一目标,但他们都不起作用。为什么 testMethod 没有被解雇?

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    // register for orientation change notification

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(testMethod)     name:@"UIDeviceOrientationDidChangeNotification" object:nil];

    [[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(testMethod)
                                             name: UIApplicationWillChangeStatusBarOrientationNotification
                                           object: nil];
    [[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(testMethod)
                                             name: UIApplicationDidChangeStatusBarOrientationNotification
                                           object: nil];
}

- (void)testMethod
{
    NSLog(@"phone was rotated");
}

最佳答案

我不小心打开了手机上的旋转锁。始终在多部手机上进行测试!

关于iphone - 不会触发任何与方向相关的通知。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11889307/

相关文章:

iphone - objective-c 中的componentsSeparatedByString是什么意思?

ios - 为什么 App 名称更改没有反射(reflect)在 iOS 7 通知中心?

iphone - heightForRowAtIndexPath 总是调用两次

ios - 通过 UITableView 保存到 SQLITE3 时的奇怪行为

ios - 使用 NSPredicate 过滤 NSDictionary 中的值并返回键数组

ios - 如何从我们的应用程序在 WhatsApp 中打开特定联系人的聊天屏幕?

iphone - 使用 NSNumberFormatter 在货币符号和值之间填充空格

iphone - 在静态库中使用时 RestKit 不工作

ios - 有没有办法使用私有(private) API 在 iOS 上自行卸载应用程序?

ios - 错误: CoreData: warning: Unable to load class named '' for entity 'Receipt' . 但是类被删除了