Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何正确发布“UIDeviceOrientationIDChangeNotification”?_Ios_Uikit_Device Orientation - Fatal编程技术网

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]当您准备再次处理它时:它将为您的视图控制器调用所有必要的回调