willRotateToInterfaceOrientation 和 deviceOrientationDidChange 之间有什么区别?
在检测方向变化并对其做出反应时,我看到了两种方法:实现 willRotateToInterfaceOrientation 或要求视图开始发出相关通知 (deviceOrientationDidChange)。
后者打算什么时候使用?会有什么好处?
In the context of detecting and reacting to an orientation change, I've seen two approaches: implementing willRotateToInterfaceOrientation
or asking the view to begin emitting relevant notifications (deviceOrientationDidChange
).
When is the latter intended to be used? What would the advantage be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
willRotateToInterfaceOrientation:duration:
方法是 UIViewController。如果您从 UIViewController 派生,则只需重写此方法即可获知方向更改。但是,如果您在其他班级并希望了解方向更改,那么您需要注册 UIDeviceOrientationDidChangeNotification。
The
willRotateToInterfaceOrientation:duration:
method is part of UIViewController. If you've derived from a UIViewController you only need to override this method to be informed about orientation changes.However, if you're in some other class and want to be informed about orientation changes then you need to register for the UIDeviceOrientationDidChangeNotification.
以“will”开头的方法在执行操作之前触发,以“did”开头的方法在执行之后触发。这就是整个框架的做法!何时使用两者之一取决于您的需要
methods that begin with "will" are triggered before action is executed, method that begin with "did" after. This is the approach of the whole framework! When to use one of the two depends on your needs