I have been successful in viewing app in portrait mode. What the problem is, when I view it in landscape, it doesn’t seem to be proper. I have implemented this code.
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
return interfaceOrientation=UIInterfaceOrientationLandscapeLeft;
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
return interfaceOrientation=UIInterfaceOrientationLandscapeRight;
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait)
{
return interfaceOrientation=UIInterfaceOrientationPortrait;
}
Should I do anything extra? Is this code helpful to me?
Change your implementation of
shouldAutorotateToInterfaceOrientation:into the following if you want to support all possible orientations:If you want to support only:
UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationLandscapeRightandUIInterfaceOrientationPortrait, then change your code into:You don’t need to look for the new orientation in
[UIApplication sharedApplication].statusBarOrientationbecause you already have it as a parameter.If you want to make the elements of the view repositioned when the device is rotated, you have to use their
autoresizingMaskproperty. Another option is to implement the methodwillRotateToInterfaceOrientation.You can change
autoresizingMaskof the elements of the view in Interface Builder in the Size Inspector. Try experimenting with different combination until you get the result you need.Finally, note that if your view is complicated or is radically different in each orientation, the best option is to use two xib files: one for portrait and one for landscape.