开发者

iPhone/iPad rotation

How can I detect the start of a rotation and the end of the rotation on these devices?

EDIT: So after your answers, how can I detect the begining and 开发者_如何学JAVAending of the orientation change.


You can implement the following two methods in your UIViewController.

To detect a start of a rotation, implement willRotateToInterfaceOrientation:duration: and to detect the end implment didRotateFromInterfaceOrientation: .

i.e.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    NSLog(@"I am starting to rotate");
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    NSLog(@"I have finished rotating");
}


You can use the UIAccelerometer api for this

EDIT to match question clarification:

Use the UIAccelerometer api for this. There is a good sample application called AccelerometerGraph that displays the 3 acceleration vectors on a graph. This should give you a good indication on how a shift in orientation will look like.


You can't detect rotation on either of these devices. The accelerometer only detects changes in velocity.

You can get a crude measure of orientation from the CLLocationManager class, which reports a heading. This value is slow to update, which limits its usefulness.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜