如何在iPhone旋转90度时触发功能?

时间:2009-06-22 20:01:50

标签: iphone

如何检测iPhone的旋转大约90度?此外,我不需要/希望屏幕本身旋转。我只是想在手机旋转时调用一个功能。谢谢!

5 个答案:

答案 0 :(得分:8)

您的视图控制器将被发送:

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

实施它以在手机旋转时执行某些操作

完成轮换后,您将获得:

  - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

这里是文档(请参阅处理视图轮换)

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html

答案 1 :(得分:1)

旋转设备时,视图控制器会收到didRotateFromInterfaceOrientation: 消息,旧方向。您可以检查interfaceOrientation属性以查看当前的旋转,并执行相应的操作。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

答案 2 :(得分:1)

您需要捕获ViewController轮换之前发送的事件。即:

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

和后轮换

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

答案 3 :(得分:1)

首先应该实现实例方法“shouldAutorotateToInterfaceOrientation”并返回YES。 然后将调用这两个方法。

答案 4 :(得分:0)

方法名称是正确的......但它们永远不会被调用。 会导致什么?