Ios 如何正确发布“UIDeviceOrientationIDChangeNotification”?
我正试图通知我的Ios 如何正确发布“UIDeviceOrientationIDChangeNotification”?,ios,uikit,device-orientation,Ios,Uikit,Device Orientation,我正试图通知我的UIViewController按设备方向重新应用布局。为此,我将UIDeviceOrientationIDChangeNotification发布到默认中心。它工作了,但没有旋转动画。我想我遗漏了一些东西。我如何才能正确发布UIDeviceOrientationIDChangeNotification?我认为当您尝试发布时不应该有任何内容。 相反,当方向发生变化时,它会自动发布。如果要使用hat通知,您应该添加一个观察者 使用: [[UIApplication sharedAp
UIViewController
按设备方向重新应用布局。为此,我将UIDeviceOrientationIDChangeNotification
发布到默认中心。它工作了,但没有旋转动画。我想我遗漏了一些东西。我如何才能正确发布UIDeviceOrientationIDChangeNotification
?我认为当您尝试发布时不应该有任何内容。
相反,当方向发生变化时,它会自动发布。如果要使用hat通知,您应该添加一个观察者 使用:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:YES];
相反(根据需要替换LandscapeRight),因为您不应该发布系统通知。它将为您发布事件:
- (void)updateOrientation
{
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
但是,当然,当您需要停止旋转时,您应该更整洁地调用[[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications]
,然后调用[[UIDevice currentDevice]BegingeratingDeviceOrientationNotifications]代码>当您准备再次处理它时:它将为您的视图控制器调用所有必要的回调