Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView has portrait dimensions while in landscape?

I have a storyboard with 1 UIViewController, holding 1 UIView that contains a number of nested UIViews. I subclassed the View Controller to implement this method:

- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

I also added

<key>UISupportedInterfaceOrientations</key>
    <array>
     <string>UIInterfaceOrientationLandscapeLeft</string>
     <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeLeft</string>

to the Info.plist.

In the viewDidLoad of the main UIView I'm doing this:

PASectionView* sectionView = [[PASectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 180)];
[self addSubview:sectionView];

The problem is the control is only 756px wide instead of the expected 1024. See the screenshot below for details. enter image description hereI've been searching all over the web but I can't find a solution to this frustrating problem anywhere. I'm using Xcode 4.5 with iOS5.1 set as base SDK.

EDIT It's working by replacing frame with bounds. However I don't understand what's happening so it isn't working with the frame size.

like image 961
s1m0n Avatar asked Jul 09 '12 12:07

s1m0n


2 Answers

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

@property(nonatomic) CGRect frame

and

The bounds rectangle, which describes the view’s location and size in its own coordinate system.

@property(nonatomic) CGRect bounds

Use bounds, not frame.

like image 176
A-Live Avatar answered Oct 19 '22 11:10

A-Live


Set the autoresizingMask to whatever views you want to autoresize on rotate. Like this:

[myView setAutoresizingMask:UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleRightMargin];
like image 45
George Avatar answered Oct 19 '22 11:10

George