如何正确发布`UIDeviceOrientationDidChangeNotification`?
我试图通知我的 UIViewController 按设备方向重新应用布局。为此,我将 UIDeviceOrientationDidChangeNotification
发布到默认中心。它有效,但没有旋转动画。我想我缺少了一些东西。如何正确发布 UIDeviceOrientationDidChangeNotification
?
I'm trying to notify my UIViewController
re-apply layout by device orientation. To do this, I'm posting UIDeviceOrientationDidChangeNotification
to default center. It worked, but without rotation animation. I think there is something I had missing. How can I post UIDeviceOrientationDidChangeNotification
properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用:
代替(根据需要替换 LandscapeRight),因为您不应该发布系统通知。
Use:
instead (replace LandscapeRight as needed), as you should not be posting system notifications.
它会为你发布事件:
但是,当然,你应该更整洁,当你需要停止旋转时调用
[[UIDevice currentDevice] endGenerateDeviceOrientationNotifications]
,然后调用[[UIDevice currentDevice] beginGenerateDeviceOrientationNotifications];
当您准备好再次处理它时:它将为您的视图控制器调用所有必要的回调。It will post events for you:
But, of course, you should be more neat and call
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]
when you need to stop rotations, and then you call[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
when you are ready to handle it again: it will call all necessary callbacks for your view controller.我认为当您尝试发布该内容时应该不会有任何内容。
相反,当方向发生变化时,它会自动发布。如果你想使用帽子通知,你应该添加一个观察者。
I don't think there should be anything when you try to post that.
Instead, it is posted automatically when there is an orientation change. You should be adding a observer for hat notification if you want to use it.