Iphone 自动调整iOS设备分辨率

Iphone 自动调整iOS设备分辨率,iphone,ios,ipad,Iphone,Ios,Ipad,到目前为止,我一直在使用if和else语句来定义iPhone或iPad上显示的对象的大小,例如: if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown){ //

到目前为止,我一直在使用if和else语句来定义iPhone或iPad上显示的对象的大小,例如:

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown){
        //For Portrait on iPhone
        [self.navBar setFrame:CGRectMake(0.0 , 0.0, 320.0f, 44.0)];

    } else if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){
        //For Landscape on iPhone
        [self.navBar setFrame:CGRectMake(0.0 , 0.0, 480.0f, 44.0)];

    }    
} else {
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown){
        //For Portrait on iPad
        [self.navBar setFrame:CGRectMake(0.0 , 0.0, 768.0f, 44.0)];

    } else if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){
        //For Landscape on iPad
        [self.navBar setFrame:CGRectMake(0.0 , 0.0, 1024.0f, 44.0)];

    }      
}
但现在我想改变它,让它更有活力。我试着使用下面的方法,但是根本没有运气

CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
有谁能帮我把这两者结合起来实施吗?我把它们混在一起的方式似乎就是问题所在。如果有人能给我一个模板,甚至是一个提示,我会非常感激


非常感谢

看来你想得太多了。为什么不只是:

[self.navBar setFrame:CGRectMake(0.0 , 0.0, self.view.frame.size.width, 44.0)];

看来你想得太多了。为什么不只是:

[self.navBar setFrame:CGRectMake(0.0 , 0.0, self.view.frame.size.width, 44.0)];

你为什么要在一个框架上使用比例呢?这毫无意义,因为帧值总是以点为单位,而不是以像素为单位……为什么要对帧使用缩放?这毫无意义,因为帧值总是以点为单位,而不是以像素为单位……嗨,伙计,我花了好几个小时试图实现这一点,但它似乎只在iPhone上起作用!在iPad上,我得到了iphone大小的值,因此导航栏很小,无法覆盖整个屏幕。还有什么额外的步骤需要我去做吗?我已经使用了NSLog来测试它,它总是给我320.00hi mate的值,我花了几个小时来实现它,但它似乎只在iPhone上起作用!在iPad上,我得到了iphone大小的值,因此导航栏很小,无法覆盖整个屏幕。还有什么额外的步骤需要我去做吗?我已经使用了NSLog来测试它,它总是给我320.00的值