views:

38

answers:

1

Hi Forum

Getting a view's bounds rect while in Landscape Mode returns the wrong sizes:

(I know there's been a lot of posts on Landscape mode, but nothing on this problem.)

Starting from a new UIView Template Project, I'm adding a single UIView to the ViewController in Interface Builder (in Landscape Mode) and setting the view size to width=400, height=200; However when I add a breakpoint in the ViewController Code: - (void)viewDidAppear:(BOOL)animated { CGRect viewRect = [testView bounds]; } the sizes are w=220, h=380! (Even though the view clearly is correct on the screen)

In myViewController.m I've set:

- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); // home button on right
}

In myAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
 application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;  //home on right
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    return YES;
}

and in the info.plist I've set: Initial interface orientation = Landscape (right home button)

I'm not trying to rotate the view with the iPhone, it is meant to be fixed in Landscape only.

Is there a workaround for this? I need to create some CALayers dependent on the correct view size.

Thanks

Steve

A: 

Sounds like a status-bar-related issue. That said I don't have a good solution for you.

In addition to looking at the frame, you can look at the bounds. Sometimes this gives better info.

William Jockusch
Thanks for your reply. It turns out I had 'Autosize subviews' on the main view controller.Sounds obvious, but since no resizing was taking place, I don't know why this should make a difference, but it's cured it.
Steve555