How can I autorotate an image from portrait to landscape mode on the IPhone?
Asked
Active
Viewed 1,930 times
3 Answers
4
You have to implement shouldAutorotateToInterfaceOrientation
method in your controller, like this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

macbirdie
- 16,086
- 6
- 47
- 54
3
Apply proper transformation to the view and adjust its frame bounds
In my app I've done it this way (very likely not the best one):
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration: 0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
self.view.bounds = CGRectMake(0.0f, 0.0f, 480.0f, 320.0f);
self.view.center = CGPointMake(160.0f, 240.0f);
[UIView commitAnimations];

Vladimir
- 170,431
- 36
- 387
- 313
-
NB: this used to be correct, but is no longer needed (Apple changed the way the API works so that this stuff happens automagically) – Adam Jan 31 '11 at 18:40
2
If you want to display a new and different view, the simplest and cleanest solution is to push a new view controller (presentModalViewController) that only supports landscape mode (in shouldAutorotateToInterfaceOrientation:).

sarfata
- 4,625
- 4
- 28
- 36
-
1– shouldAutorotateToInterfaceOrientation: Deprecated in iOS 6.0. See [this](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIViewController/shouldAutorotateToInterfaceOrientation:). – JohnK Jun 20 '13 at 23:01