如何在没有设备自动旋转的情况下检测 iPhone 上的旋转? [英] How do I detect a rotation on the iPhone without the device autorotating?

查看:29
本文介绍了如何在没有设备自动旋转的情况下检测 iPhone 上的旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道怎么做吗?

我是这么想的:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
}

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}

- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
}

- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
}

可能会阻止设备旋转(覆盖我的 UIViewController 的所有旋转方法而不调用超类),但我担心实际执行旋转的不是 UIViewController.

may prevent the device from rotation (overriding all rotate methods of my UIViewController and not calling the superclass) but I fear it's not the UIViewController that actually performs the rotation.

我的 UIViewController 在 UINavigationController 中.

My UIViewController is in a UINavigationController.

有人有什么想法吗?

干杯,尼克.

推荐答案

你可以注册通知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.

这篇关于如何在没有设备自动旋转的情况下检测 iPhone 上的旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆