2

有人知道怎么做吗?

我是这样想的:

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

有人有想法么?

干杯,尼克。

4

3 回答 3

20

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

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

当您不再关心方向更改时,请调用此方法:

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

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

于 2009-06-15T16:29:39.663 回答
4

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

于 2009-06-15T20:26:30.747 回答
1

YES从回来shouldAutorotateToInterfaceOrientation:,我怀疑你不是故意的。这是您需要实施以防止设备旋转的唯一方法。

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

于 2009-06-15T12:36:41.633 回答