I have an UIImage inside an UIImageView in my application.
In portrait mode, the image is centered but when I switch to the landscape mode it stills on the left.
So I added the following method in my .m file but the problem is that I have a TabBar application, so when I rotate the device on another tab and I go back to the tab containing the image, it doesn’t rotate automatically.
There is a way to rotate automatically all the elements of the application when rotating the device on any tab ?
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){
background.image = [UIImage imageNamed:@"back2-landscape.png"];
} else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){
background.image = [UIImage imageNamed:@"back2-portrait.png"];
}
}
Thank you 🙂
There are two options:
*1. Do in in IB – Turn off all those little spaces and arrows in the “Autosizing” area under the “Size Inspector”. You should be able to then “Simulate Interface”, and rotate the [simulated] device, with the object staying centered.
*2. Do it programmatically, in didRotateFromInterfaceOrientation by doing something like: