2012-11-22 104 views
1

我使用通知来获取设备的方向。屏幕旋转锁定时如何获取设备方向?

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [notificationCenter addObserver:self 
            selector:@selector(deviceOrientationDidChange)   
             name:UIDeviceOrientationDidChangeNotification 
            object:nil]; 

但是当设备的屏幕旋转被锁定时不会调用选择器功能。任何帮助?

+0

是否正确设置了“notificationCenter”?检查它是否不是零。您也可以尝试以下语法:[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange)name:UIDeviceOrientationDidChangeNotification object:nil]; – rdurand

回答

2

您可以使用加速计来获取屏幕方向的值。请参阅this。另请参阅this博客

相关问题