-1

I'm making an ios app, I want to make all pages are landspace. The first page is landspace, but the second page is portrait (going the second page via button). How to make it landspace.

(I'm not using storyboard)

Button click event:

PanelController *panel = [[PanelController alloc] init];
[self.navigationController pushViewController:panel animated:true];

enter image description here

enter image description here

Kemal Duran
  • 1,478
  • 1
  • 13
  • 19
  • Did you read the View Controller documentation? Info on autorotation and the code required: https://developer.apple.com/library/ios/featuredarticles/viewcontrollerpgforiphoneos/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html – Robotic Cat Sep 14 '14 at 19:58

2 Answers2

2

How about this ?

-(void)viewWillAppear:(BOOL)animated
{
    UIApplication* application = [UIApplication sharedApplication];
    if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
    {
        UIViewController *controller = [[UIViewController alloc]init];
        [controller.view setBackgroundColor:[UIColor whiteColor]];
        [self.navigationController presentViewController:controller animated:NO completion:^{
            [self.navigationController dismissViewControllerAnimated:YES completion:^{
            }];
        }];
}
B.I.A
  • 700
  • 1
  • 7
  • 20
0

The correct technique for changing orientation should be this:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}
LS_
  • 6,763
  • 9
  • 52
  • 88
  • where should I put them? – Kemal Duran Sep 14 '14 at 19:49
  • I can't test it right now but I think you should use it after your ViewDidLoad on every .m file. (Maybe you just need it on your first ViewController, give it a try!) – LS_ Sep 14 '14 at 19:51
  • Also if my method doesn't work take a look at this answer! http://stackoverflow.com/questions/5777313/xcode-how-to-build-a-landscape-only-iphone-programe – LS_ Sep 14 '14 at 19:53