[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
这一行代码的作用是什么?
查阅其他帖子时看到:
必须调用beginGeneratingDeviceOrientationNotifications方法后,此orientation属性才有效,否则一直是0。
但我发现写不写beginGeneratingDeviceOrientationNotifications这个方法,都可以正常添加如下通知:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceOrientationDidChange)
name:UIDeviceOrientationDidChangeNotification
object:nil];
并且在通知的执行方法deviceOrientationDidChange中,能够正常的接收到设置正确的旋转方向
同理,[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];这个方法也没有看到用处,执行完以后依旧能够正常获取到设备旋转的通知,除非把UIDeviceOrientationDidChangeNotification remove掉
所以在此求问beginGeneratingDeviceOrientationNotifications和endGeneratingDeviceOrientationNotifications的具体用途。