Reputation: 1319
How do I detect the rotation of the iPhone for approximately 90 degrees? Additionally, I don't need/want the screen itself to rotate. I just want to call a function when the phone has been rotated. Thanks!
Upvotes: 5
Views: 4602
Reputation: 11
you should first implement the instance method "shouldAutorotateToInterfaceOrientation" and return YES. and then the two method will be called.
Upvotes: 1
Reputation: 289
The method names are correct... but they never get called. What would cause that?
Upvotes: 0
Reputation: 15011
You need to catch the events sent prior to ViewController rotation. Namely:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
and post rotation
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
Upvotes: 1
Reputation: 2966
When you rotate the device, your view controller receives a didRotateFromInterfaceOrientation: message, with the old orientation. You can check the interfaceOrientation property to see the current rotation, and do something accordingly.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
Upvotes: 1
Reputation: 89192
Your view controller will be sent:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Implement it to do something when the phone is being rotated
After the rotation is done, you get:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
Here it is in the docs (see Handling View Rotations)
Upvotes: 8