18
votes

I am using a splitView in iPad app. the detail view has 2 subView in it that draws themselves according to the etail view bounds. the problem is that they always draw themselves in (1024, 768) even when the ipad is in landscape mode.

BTW - if i call then in portrait mode and then rotate the ipad they do scale to (706,768).

I have checked the detail view frame and bounds as it created (in the view did load method) and in both cases i get this:

NSLog(@"screen frame = %@",NSStringFromCGRect(self.view.frame));
NSLog(@"screen bounds = %@",NSStringFromCGRect(self.view.bounds));

In the debug window I get:

2011-03-03 10:58:19.376 English Club[63347:207] screen frame = {{0, 0}, {768, 1024}}
2011-03-03 10:58:19.382 English Club[63347:207] screen bounds = {{0, 0}, {768, 1024}}

I cannot find out where the problem is. Can anyone help me?

Thanks for any help.

6
I have also noticed this odd issue. I would recommend filing a bug report with Apple - that's what I did. bugreporter.apple.comJasarien
Did Apple answer to this bug filing? Btw, how are you adding those subviews to the main view? Are you properly setting the autoresize properties on them? Can you show us more code to get deeper into your problem? thank youmarzapower
So, Here what do you actually want to do? Do you want to set the size of view of detail view. or the view inside detail view. You can set the frame size of view inside detail view but not the size of detail view because the base size of the view will remain standard as per the splitviewcontroller. Please let me know if you have different question.AppAspect

6 Answers

6
votes

In viewDidLoad the view is not supposed to have its real size. That is set up later by layout methods. But that shouldn't stop you :) How do you set your autoresizing mask? If you have set it correctly, everything should be ok.

4
votes

if you wait for -(void)viewDidLayoutSubviews it will have the right size

3
votes

I am currently writing a UISplitViewController app, and was disappointed to find out changing the the size of the detail or master view is forbidden. It is totally in charge of the size of the those sub frames.

Like UINavigationController and UITabBarController, UISplitViewController is a 'container' view controller, and it shapes it's subviews to fit it's purposes.

The function self debugDumpTheFrames prints out the uisplitviewcontroller's frame and it's two subframes. I print the frames in the splitViewController's viewDidLoad, and set a timer to call this function a second time 2 seconds later (during which time i Do nothing):

[self debugDumpTheFrames];
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(debugDumpTheFrames) userInfo:nil repeats:NO];

If we look at the output, we can see that sometime after viewdidload, the UISplitViewController has changed the frames of it's subviews.

size of splitviewcontrollers view frame {{0, 0}, {748, 1024}}
size of splitviewcontrollers detail view frame {{0, 0}, {768, 1024}}
size of splitviewcontrollers master view frame {{0, 0}, {768, 1024}}

size of splitviewcontrollers view frame {{0, 0}, {748, 1024}}
size of splitviewcontrollers detail view frame {{321, 0}, {703, 748}}
size of splitviewcontrollers master view frame {{0, 0}, {320, 748}}

Where exactly it does this resizing I am unsure; but the uisplitviewcontroller is the boss of those frames, and they are private properties so touching them is grounds for rejection from the store.

3
votes

Do your operations in viewWillAppear instead of viewDidLoad.

1
votes

Yes If you have set Autoresizing property it should be ok..

You can set them via nib or by code

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

cheers...

0
votes

If you really do need to get the correct width in viewDidLoad, you can access the split view controller and get the width of the detail view controller.

E.g. in Swift:

func getDetailViewSize() -> CGSize {
    var detailViewController: UIViewController
    if (self.splitViewController?.viewControllers.count > 1) {
        detailViewController = self.splitViewController?.viewControllers[1] as! UIViewController
    } else {
        detailViewController = self.splitViewController?.viewControllers[0] as! UIViewController
    }
    return detailViewController.view.frame.size
}