Pregunta

i have a application that supports only a portrait mode. but need to change orientation to landscape for a single view controller. i saw more answers here for this.

but i cant implement that. i created new single view application now. a view controller has a button. i want to change Orientation of view controller when i click the button.

#import "pixViewController.h"
#import "pixNextViewController.h"
@interface pixViewController ()
- (IBAction)changeOrientation:(id)sender;

@end



@implementation pixViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)changeOrientation:(id)sender {

}

@end

what code should be there in changeOrentaion method..?

¿Fue útil?

Solución

You can override:

- (BOOL)shouldAutoRotate

for each view controller in your project, and return YES for the one where you want allow rotation.

Then, also override supportedDeviceOrientations and specify what you want in there. For example:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

Be sure to set up the allowed orientations correctly in your target's General settings. In other words, have your project allow multiple orientations, but just don't allow rotation in the individual view controller classes where you don't want rotation.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top