1
votes

I started off with an tabbar application which has 2 views(firstviewcontroller and secondviewcontroller).the second view controller does not have a background image but the first one does.

i have 2 images one for protrait and one for landscape. all i want to do is load an background image whenever the orientation is changed. i want to support all orientations.

here is my viewdidload method

-(void)viewDidLoad 
{
    imgview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgportrait.png"]];
    [imgview setFrame:CGRectMake(0, 0, 768, 1024)];
    [self.view addSubview:imgview];
    [self.view sendSubviewToBack:imgview];
    [imgview release];
}

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { NSLog(@"in shouldrotate"); return YES; }

(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == (UIInterfaceOrientationPortrait || UIInterfaceOrientationPortraitUpsideDown))
{
    NSLog(@"in portrait");
}
else if (toInterfaceOrientation == (UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight))
{
    NSLog(@"in landscape");
}

}

in the willRotateToInterfaceOrientation it never goes into any of the if loop and it doesnt print the log, i am not sure why its not matching the orientation to either of them. i just want to set the appropriate backgroundimage to the firstviewcontroller. i know it should be very simple but i am not able to get it right.

1
Please format your code. While editing your question, there is a {} symbol just above the editor that will format your code appropriately.darioo

1 Answers

2
votes

check your condition like this

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation==UIInterfaceOrientationPortrait || 
       toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
    {
       NSLog(@"in portrait");
    }
    else
    {
        NSLog(@"in landscape");
    }
}