I am working on an App where I want to show a modal view controller when the user rotates the de开发者_开发技巧vice. It should dismiss when the user rotates it back to portrait. During the rotation, the main view controller shouldn't be rotated.
How can I manage that?
I tried putting the code into the shouldAutorotateToInterfaceOrientation:
method for showing the modal view controller, but I got always an error.
Some ideas?
In the appDelegate you could use
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
and define the method
- (void) didRotate:(NSNotification *)notification
In this method, fetch the new orientation and apply or remove the modal view controller.
In shouldAutorotateToInterfaceOrientation:
limit the original view to only accept the one orientation you want it to have.
you need to put this code in the
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
method of your view controller. Basically you will set your shouldAutorotateToInterfaceOrientationMethod:
to return TRUE for any orientations you want to support (including the modal view popup). and then in the first method listed you implement the modal view controller becoming active.
精彩评论