Steven
Steven

Reputation: 1098

Determining screen dimensions on device rotation

I'm making use of [[UIScreen mainScreen] bounds] for the basis of framing a lot of sub-views. I'm also making use of values from [[UIApplication sharedApplication] statusBarFrame] and self.navigationController.toolbar.frame to ultimately determine the framing of useful view space I can make use of in the app.

I'm seeing problems as I try to handle device rotation. With some debugging, I'm learning that the values I get from the methods above aren't necessarily what I'm looking for.

In short, no matter the device rotation, I'm ultimately looking for the size of the view (screen minus status and navigation control toolbar) that is my working area. How do you advise I obtain this size/frame?

Thanks.

Upvotes: 1

Views: 650

Answers (2)

Steven
Steven

Reputation: 1098

Resolved this by following information on this post - stackoverflow.com/q/7905432/870345. My code:

- (CGSize)currentSize
{
    CGSize size = [UIScreen mainScreen].bounds.size;
    UIApplication *application = [UIApplication sharedApplication];
    if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
        size = CGSizeMake(size.height, size.width);
    }
    if (application.statusBarHidden == NO) {
        size.height -= MIN(application.statusBarFrame.size.width, application.statusBarFrame.size.height);
    }
    size.height -= self.navigationController.navigationBar.frame.size.height;
    return size;
}

Upvotes: 1

Mario
Mario

Reputation: 4520

Probably not he best way, but you could drop a UIView on your view and set its springs and struts so that it autosizes and stays full screen. Then get the frame via outlet to this view.

Upvotes: 0

Related Questions