如何在 iPhone 不自动旋转的情况下检测旋转?

发布于 2024-07-24 15:50:46 字数 1125 浏览 3 评论 0原文

有人知道怎么做吗?

我认为这:

-(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 。

我的 UIViewController 位于 UINavigationController 中。

有人有主意吗?

干杯, 缺口。

Anyone know how to do this?

I thought this:

-(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 {
}

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.

My UIViewController is in a UINavigationController.

Anyone have any ideas?

Cheers,
Nick.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

影子的影子 2024-07-31 15:50:46

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

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

当您不再关心方向变化时,调用此方法:

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

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

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];

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

暮倦 2024-07-31 15:50:46

附带说明一下,在 2.x 中,shouldAutoRotateToInterfaceOrientation 曾经在旋转时被调用,但在 3.0 中,它的一致性要差得多。 另一篇文章中提到的通知是可靠的轮换指示的方法。

On a side note shouldAutoRotateToInterfaceOrientation used to be called on the time for rotation in 2.x, but in 3.0 it's much less consistent. The notification mentioned in the other post is the way to go for reliable indication of rotation.

七色彩虹 2024-07-31 15:50:46

您从 shouldAutorotateToInterfaceOrientation: 返回 YES,我怀疑您无意这样做。 这是防止设备旋转所需实施的唯一方法。

至于获取设备的当前方向,可以使用[[UIDevice currentDevice]orientation]

You're returning YES from shouldAutorotateToInterfaceOrientation:, which I suspect you didn't mean to do. That's the only method you need to implement to prevent the device from rotating.

As for getting the current orientation of the device, you can use [[UIDevice currentDevice] orientation].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文