0
votes

So I wanted to add a UIViewController with width 450 and height of the screen, so if it's portrait then the height is 1024 and if it's landscape then the height is 768. This view controller, called ProfileViewController has a xib that is set at 450 and 1024. Auto-resize is set to have flexible height.

 profViewController = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil];
            self.profileViewController_ = profViewController;
            [profViewController release];

So inside ProfileViewController I am also initializing another view controller called FeedsViewController. Now the issue is that in profViewController viewDidLoad's the height is always set to 1024 no matter what the orientation is. How do I have this so that it adjusts to what my orientation is? I've tried setting the bounds of profViewController but then this change is reflected after the viewDidLoad.

4

4 Answers

0
votes

If you set the FeedsViewController view's frame in the same manner that you've set the ProfileViewController view's frame in the NIB, then things should automatically resize correctly. That is, you give it an initial size that's what you want relative to the outer view, then let the system's auto-resize behaviour take things from there.

Try something like this inside ProfileViewController's viewDidLoad:

// create and init self.feedsViewController
// ...

CGRect b = self.view.bounds;
self.feedsViewController.view.frame = CGRectMake((b.size.width - 450) / 2, 0, 450, b.size.height);
self.feedsViewController.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
0
votes

For finding the height and width, try this

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
0
votes

override following method of profViewController

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, 450, 1024);

}
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, 450, 768);
    }
}
0
votes

If you want change your tableview frame, you should do it in viewDidAppear: instead of viewDidLoad:.