0

I have two view (view 1 and view 2). view1 contain a button and when i clicked on this button i go to view 2. i want to show view2 with orientation Portrait and Landscape. for view2 i create 2 UiviewController one for landscape orientation and seconde for Portrait orientation and with same same Class.but does not work. any one have any idea?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
     return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
BERGUIGA Mohamed Amine
  • 6,094
  • 3
  • 40
  • 38

1 Answers1

0

Why do you need TWO ViewControllers just for the purpose of Orientation ..?

HEre Simple scenario ,

Create 2 Views

  1. Portrait &&
  2. Landscape View , As per your requirement .

Follow something like this .

-(BOOL)shouldAutorotate{
    return YES;
}

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self orientationChanged:toInterfaceOrientation];
}

-(void)orientationChanged:(UIInterfaceOrientation)orientation{
    NSLog(@"orientation change");
   // UIDeviceOrientation deviceOrientation = [[object object] orientation];

    if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown){
        NSLog(@"Changed Orientation To Portrait");
        self.viewPortrait.hidden = NO;
        self.viewLandscape.hidden = YES;
    }

else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){
    NSLog(@"Changed Orientation To Landscape");

    self.viewPortrait.hidden = YES;
    self.viewLandscape.hidden = NO;
    }  
}

And You should set for which all orientation required .

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}
Kumar KL
  • 15,315
  • 9
  • 38
  • 60