且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有设备自动旋转的情况下检测 iPhone 上的旋转?

更新时间:2022-05-02 22:08:57

你可以注册通知UIDeviceOrientationDidChangeNotification(来自UIDevice.h),然后当你关心关于方向变化调用这个方法:

You can register for the notification UIDeviceOrientationDidChangeNotification (from UIDevice.h), and then when you care about orientation changes call this method:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

当你不再关心方向变化时,调用这个方法:

When you no longer care about orientation changes, call this method:

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

通知将在适用时发送,您可以检查 [UIDevice currentDevice].orientation 了解当前方向是什么.

The notification will be sent when applicable, and you can check [UIDevice currentDevice].orientation to find out what the current orientation is.