views:

394

answers:

1

Hi, I have added new Xib view file in my project. I assigned to view controller and in the view controller I set:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    //return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    return YES;
}

But when the application runs in landscape mode, xib is not in landscape mode. I have set in info.plist file also xib file is also in landscape view. What do I have to do? Any help?

A: 

You need to adjust the alignment of elements on your view in the way, that when it rotates the elements will take their place according to orientation.

for example if you have a button on your left bottom corner, in the alignments pane you should assign it to stick to left and bottom, while maintaining its original size. Also the containing view has to be fully autoresizable.

You can do it from the code like this:

self.view.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

Hope this helps

Nava Carmon
sir, i have added , i have same issue
Mikhail Naimy
do you need this view show in portrait and in landscape, or only in landscape? If you need it to show in both, you have to change ALL subviews in your view to have proper alignment. If you need your view ONLY in landscape, you can design it in IB in landscape mode. To achieve this, find a small circular arrow on the top right side of the view editor. If you press it, the editor will change to landscape mode and you can edit your view in landscape, so it will show properly in landscape.
Nava Carmon
Hi, when I used IB to design in landscape mode, the view does not rotate to landscape, but it is in the landscape "shape" (the wide and short size) displayed in portrait mode. What am I missing? I have edited the plist file, the code you have from above, but it still does not work. (the keyboard is rotated correctly however)...
confusedKid