简体   繁体   English

检查iOS设备方向

[英]Checking iOS device Orientation

每次iOS设备更改方向时,我都需要获取iOS设备的方向。记住,不要在应用启动时或加载时记住,因为每一次设备更改方向时,我都需要注册它。

you have to Listen/observe/watch for device orientation changes UIDeviceOrientationDidChangeNotification , 您必须侦听/观察/观看设备方向更改UIDeviceOrientationDidChangeNotification

See same question here 在这里看到相同的问题

As per apple UIKit Framework Reference following method called every time when device orientation changed. 根据Apple UIKit Framework Reference,每次更改设备方向时都会调用以下方法。

For iOS8 and later 对于iOS8及更高版本

Notifies the container that the size of its view is about to change. 通知容器其视图的大小即将更改。 (required) (需要)

- (void)viewWillTransitionToSize:(CGSize)size
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

Parameters 参量

size - The new size for the container's view. size-容器视图的新大小。

coordinator - The transition coordinator object managing the size change. 协调器-管理大小更改的过渡协调器对象。 You can use this object to animate your changes or get information about the transition that is in progress. 您可以使用该对象来制作更改的动画或获取有关正在进行的过渡的信息。

Discussion 讨论区

UIKit calls this method before changing the size of a presented view controller's view. UIKit在更改显示的视图控制器的视图的大小之前调用此方法。 You can override this method in your own objects and use it to perform additional tasks related to the size change. 您可以在自己的对象中覆盖此方法,并使用它执行与尺寸更改有关的其他任务。 For example, a container view controller might use this method to override the traits of its embedded child view controllers. 例如,容器视图控制器可能使用此方法来覆盖其嵌入式子视图控制器的特征。 Use the provided coordinator object to animate any changes you make. 使用提供的协调器对象为您所做的任何更改制作动画。

If you override this method in your custom view controllers, always call super at some point in your implementation so that UIKit can forward the size change message appropriately. 如果在自定义视图控制器中重写此方法,请始终在实现中的某个时刻调用super,以便UIKit可以正确转发大小更改消息。 View controllers forward the size change message to their views and child view controllers. 视图控制器将大小更改消息转发到其视图和子视图控制器。 Presentation controllers forward the size change to their presented view controller. 演示控制器将大小更改转发到其演示的视图控制器。

For iOS2 upto iOS8 对于iOS2至iOS8

Sent to the view controller after the user interface rotates. 用户界面旋转后发送到视图控制器。

Deprecation Statement 弃用声明

Use viewWillTransitionToSize:withTransitionCoordinator: to make interface-based adjustments. 使用viewWillTransitionToSize:withTransitionCoordinator:进行基于界面的调整。

Declaration 宣言

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

Parameters 参量

fromInterfaceOrientation - The old orientation of the user interface. fromInterfaceOrientation-用户界面的旧方向。 For possible values, see UIInterfaceOrientation. 有关可能的值,请参见UIInterfaceOrientation。

Discussion 讨论区

Subclasses may override this method to perform additional actions immediately after the rotation. 子类可以重写此方法以在旋转后立即执行其他操作。 For example, you might use this method to reenable view interactions, start media playback again, or turn on expensive drawing or live updates. 例如,您可能使用此方法重新启用视图交互,再次开始媒体播放或打开昂贵的图形或实时更新。 By the time this method is called, the interfaceOrientation property is already set to the new orientation. 在调用此方法时,interfaceOrientation属性已经设置为新的方向。 Your implementation of this method must call super at some point during its execution. 此方法的实现必须在执行过程中的某个时候调用super。

This method is called regardless of whether your code performs one-step or two-step rotations. 无论您的代码执行单步旋转还是两步旋转,都将调用此方法。

Source - UIKit Framework Reference (hope this helpful to you) 来源-UIKit框架参考 (希望对您有所帮助)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM