ios - 检测 iOS 中的旋转变化

标签 ios interface nsnotificationcenter screen-rotation autorotate

我正在制作一个 iOS 应用程序,需要在旋转时对界面进行一些重新排列。我试图通过实现 - (void)orientationChanged:(NSNotification *)note 来检测这一点,但这会在设备面朝上或面朝下时通知我。

我想要一种在界面改变方向时得到通知的方法。

最佳答案

有几种方法可以做到这一点,您可以在 UIViewController class reference 中找到它们:

– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:

您也可以在 viewWillLayoutSubviews 方法中执行此操作,但要小心使用它,因为它也会在屏幕外观上以及您添加 subview 时调用。

编辑:

解决方案现已弃用,请参阅已接受的答案。

关于ios - 检测 iOS 中的旋转变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14369251/

相关文章:

ios - 在 Swift 中计算树的平均水平时如何跳过 nil 值

pointers - 如何在 golang 中获取指向通过 interface{} 传递的结构的指针?

iphone - NSNotification 被多次引发

Swift- 使用 NSNotification 在 SpriteKit 中展示广告?

ios - 更改日期选择器的模式

ios - SKAction 在 appDidBecomeActive() 时恢复,即使游戏在 appDidResignActive() 之前暂停

ios - 尝试以编程方式了解 iOS 9.3 支持的布局约束

c# - 使用继承接口(interface)的不同对象

java - 接口(interface)的引用可以= null吗?

ios - Objective C View 不随键盘移动