Reputation: 19869
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.
Upvotes: 18
Views: 8329
Reputation: 4845
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
}
Upvotes: 1
Reputation: 145
if you wait for -(void)viewDidLayoutSubviews it will have the right size
Upvotes: 4
Reputation: 123
Do your operations in viewWillAppear instead of viewDidLoad.
Upvotes: 3
Reputation: 652
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.
Upvotes: 3
Reputation: 476
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...
Upvotes: 1
Reputation: 130102
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.
Upvotes: 6