开发者

Does [[UIScreen mainScreen] bounds] return values respond to orientations?

开发者 https://www.devze.com 2023-02-01 05:26 出处:网络
So basically 开发者_StackOverflowmy question that. Does the bounds CGRect change with the screen orientation or is it static?

So basically 开发者_StackOverflowmy question that. Does the bounds CGRect change with the screen orientation or is it static?

Thanks!


Just tested that on iPhone simulator - it always returns the same value for all orientations

{{0, 0}, {320, 480}}


I created a property to return the screen bounds, taking into consideration the orientation of the device.

- (CGRect)boundsWithRespectToOrientation
{
    CGRect bounds = self.bounds;

    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) && bounds.size.height > bounds.size.width)
        bounds = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.height, bounds.size.width);
    else if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) && bounds.size.width > bounds.size.height)
        bounds = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.height, bounds.size.width);

    return bounds;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消