Tutorial :New View when device is rotated



Question:

I want to call "presentmodalviewcontroller" when the iPhone / iPod Touch is rotated to landscape mode with a flip animation. When it gets rotated back to portrait, I want to present the first view again, again with the flip animation.

Weren't able to find something working on the web :(

I'm sure you can help me :) Thanks a lot ! Sebastian


Solution:1

In your UIViewController, accept all interface orientations:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  {  return YES;  }  

And your controller will start receiving rotation messages, like:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration  

and

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation  

Where you can react to rotation and do things like present/dismiss modal viewcontrollers.


Solution:2

Try listening for the UIDeviceOrientationDidChangeNotification notification:

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];

When you get on it, present your controller.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »