Вопрос

Why would [UIScreen mainScreen].bounds.size.height always return 1024 no matter what layout mode the iPad app is in?

I am trying to have a custom view dynamically generated based on layout mode and I always get a height of 1024 back?

+ (CGRect)rectForView {
NSLog(@"The height is %f", [UIScreen mainScreen].bounds.size.height );
return CGRectMake( 0.0f, 0.0f, [[UIScreen mainScreen]bounds].size.width, (([UIScreen mainScreen].bounds.size.height ) - 100));
}
Это было полезно?

Решение

Here is what I did to fix it.

+ (CGRect)rectForView {

if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {

    return CGRectMake( 0.0f, 0.0f, [[UIScreen mainScreen]bounds].size.height, (([UIScreen mainScreen].bounds.size.width ) - 100));

}

NSLog(@"The height is %f", [UIScreen mainScreen].bounds.size.height );
return CGRectMake( 0.0f, 0.0f, [[UIScreen mainScreen]bounds].size.width, (([UIScreen mainScreen].bounds.size.height ) - 100));
}

Другие советы

This is correct functionality for the bounds and I believe it returns the size of the screen in the orientation it was launched. You will need to look at viewController or navigation controller for the appropriate size of the frame which is dependent on the orientation.

It always returns the coordinates in Portrait mode. You have to change it if you have another orientation.

UIScreen *screen = [UIScreen mainScreen];
CGRect screenRect = screen.bounds; // implicitly in Portrait orientation.

if (UIDeviceOrientationIsLandscape(orientation)) {
    CGRect temp;
    temp.size.width = screenRect.size.height;
    temp.size.height = screenRect.size.width;
    screenRect = temp;
}

The above code is directly taken from OLGhostAlertView.m which is a free alert view available online, but it gives you an idea as to how to get the coorect coordinates.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top