Does UIView have portrait dimensions in a landscape?

I have a storyboard with 1 UIViewControllerholding 1 UIViewthat contains several 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>

c Info.plist.

In the viewDidLoad of the main UIView, I do this:

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

The problem is that only 756px is used for control instead of the expected 1024. For more details, see the screenshot below. enter image description hereI searched all over the network, but I can’t find a solution to this annoying problem anywhere. I am using Xcode 4.5 with iOS5.1 installed as the base SDK.

EDIT It works by replacing frames with frames. However, I do not understand what is happening, so it does not work with the frame size.

+5
4

, .

@property () CGRect frame

, .

@property () CGRect

, .

+11

autoresizingMask , . :

[myView setAutoresizingMask:UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleRightMargin];
+2

, ​​ [PASectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 180)]; [self addSubview:sectionView];, , [PASectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)]; [self addSubview:sectionView];, UIView, ViewDidLoad. , .h: PASectionView * sectionView; .m

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{

}
else  // OrientationLandscape
{
sectionView.frame = CGRect(sectionView.frame.origin.x,sectionView.frame.origin.y,self.view.frame.size.width,180);    
}
0

,

Add this line of code before adding subView to the supervisor if your subView is added by code. yourSubView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

else, if your subView is added to the nib file, select the boundary magnets and masks to resize in the subView property in the nib file.

0
source

All Articles