Descendant viewview viewer viewer height after iOS

I searched, but cannot find the answer to this question that I have. This seems pretty fundamental, so hopefully someone can explain or point me to a previous post.

When I add a view to the viewcontroller as a subtitle of another view manager, I find that the subexpression height property vanishes during rotation. Width is also increasing.

For example, if the NSDChildViewController view is set to 50x100 in the xib file ...

@implementation ParentViewController

-(void)viewDidLoad
{
  [super viewDidLoad];
  mChild = [[ChildViewController alloc] initWithNibName:nil
                                                  bundle:nil];
  [self.view addSubview:mChild.view];
}

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [mChild printFrame];
}
@end

@implementation ChildViewController

-(void)printFrame
{
    NSLog(@"%s %@",__FUNCTION__, NSStringFromCGRect(self.view.frame));
}
@end

The record for orientation orientation portrait-> landscape-> portrait is as follows:

- [PictureFrame ChildViewController] {{0, 0}, {50, 100}}

- [PictureFrame ChildViewController] {{0, 0}, {298, 0}}

- [PictureFrame ChildViewController] {{0, 0}, {50, 248}}

? . , , - 50x100, - ...

-(void)forceSize
{
    CGRect frame = self.view.frame;
    frame.size.width=50;
    frame.size.height=100;
    self.view.frame=frame;
}

. .

+4
1

. , .

, 4- iPhone- ( ), , : 320 x 568. .

:

:

widthDifference = parentViewWidth - originalChildViewWidth      // 270 (320 - 50)
heightDifference = parentViewHeight - originalChildViewHeight   // 468 (568 - 100)

:

childLandscapeViewWidth = parentViewHeight - widthDifference    // 298 (568 - 270)
childLandscapeViewHeight = parentViewWidth - heightDifference   // -148 (320 - 468)
    // (but height cannot be < 0, so this is automatically set to 0)

, child = 298 height = 0

:

widthDifference = parentViewWidth - childLandscapeViewWidth     // 270 (568 - 298)
heightDifference = parentViewHeight - childLandscapeViewHeight  // 320 (320 - 0)

:

childPortraitViewWidth = parentViewWidth - widthDifference      // 50 (320 - 270)
childPortraitViewHeight = parentViewHeight - heightDifference   // 248 (568 - 320)

child = 50 height = 248

, , autoresizesSubviews (, YES) NO :

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.autoresizesSubviews = NO;
    ...
}
+3

All Articles