需要获取设备方向变化(UIDeviceOrientation)的消息

时间:2023-03-09 17:08:34
需要获取设备方向变化(UIDeviceOrientation)的消息

如果需要获得UIDeviceOrientation的转换消息的话,只需要:

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
 [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(orientationChanged:)
                                              name:UIApplicationDidChangeStatusBarFrameNotification
                                                   object:nil];

在结束时候,需要移除注册的通知(dealloc)

[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
- (void)orientationChanged:(NSNotification *)notification
{
    ...
}