0
votes

Can Anyone explain me how to give the Support for Landscape and Portrait orientations in iOS 7 iPad using auto layout or programatically .

I have tried with @"will rotate Method" programatically and also auto layouts.. but both these are not working Properly for.

Don't know where I m Making the mistake

Please check this below code for reference and correct me

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
     NSLog(@"Landscape left");
     NSLog(@"Landscape left  : %@",LoginBackgroundView);
     LoginViewObj.loginBackgroundImage.frame= CGRectMake(0 , 0, 1024, 768);
     LoginViewObj.LoginBackgroundView.frame =CGRectMake(346, 228, 337, 300);


} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    NSLog(@"Landscape right");
    LoginViewObj.loginBackgroundImage.frame= CGRectMake(0 , 0, 1024, 768);
    LoginViewObj.LoginBackgroundView.frame =CGRectMake(346, 228, 337, 300);



} else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
    NSLog(@"Portrait");
     NSLog(@"potrait : %@",LoginBackgroundView);
     LoginViewObj.loginBackgroundImage.frame= CGRectMake(0 , 0, 768, 1024);
     LoginViewObj.LoginBackgroundView.frame =CGRectMake(0, 330, 337, 300);


} else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
     NSLog(@"Upside down");
     LoginViewObj.loginBackgroundImage.frame= CGRectMake(0 , 0, 768, 1024);
     LoginViewObj.LoginBackgroundView.frame =CGRectMake(0, 330, 337, 300);

}

}

2

2 Answers

0
votes

(the old way) to support all interface orientations on <= iOs 5.. put this in your viewController

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{


    return YES;

}

(the current way) to support all interface orientations on >= iOs 6.. put these in your viewController, and select the supported orientations in the 'general'(first) tab of your target settings...

- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0){
  return YES;
}
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0){

    return UIInterfaceOrientationMaskAll;
}

you can have both of these in there no problem if you're targeting all the way back to iOs5.

0
votes

Got the solution with this

 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
    // here for landscape mode frames

}

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {

    LoginBackgroundView.frame =CGRectMake(200, 330, 337, 300);
    loginBackgroundImage.frame= CGRectMake(0   , 0, 768, 1024);
    loginBackgroundImage.image = [UIImage imageNamed:@"Login_potrait.png"];
    footerView.frame= CGRectMake(0, 980,768, 50);
    logoImage.frame = CGRectMake(220, 197, 258, 105);
}

}

Now the controls are working correctly with both the orientations