简体   繁体   中英

xcode 6 asset catalog iphone 6

this problem still hasn't been answered. when using the asset catalog, device specific (not universal), the options are 1x, 2x, r 2x, 3x. 1x is unnecessary as it is not retina. 2x is the well for ip4 with a res 640x960. r 2x is the well for ip5 with a res 640x1136. 3x is the ip6plus well with a res of 1242x2208.

now when i run the simulator for ip6 (not ip6plus!), it uses the 2x image (640x960 res for ip4) and it is also not upscaling to fill the screen (which wouldn't make sense anyhow as the ratios don't fit).

has anyone found a proper guide for setting up background images for the new phones? i don't mean the explanation how the various res sizes are scaling, that's clear, but how to work around the obvious mismatch between the xcassets image well @2x that shares ip4 and ip6? thanks!

edit: Xcode asset catalog support for 3.5", 4", and 4.7" @2x images? similar question but not really solved, just a workaround by using universal instead of device specific. anyone know a better way?

I have reported a bug to Apple about this since mid November 2014 and I just noticed they marked it as No Value... which gives me the impression Apple has omitted an additional slot for iPhone 6 on purpose. My guess is they now want the 2x slot to be used for iPhone 6, and maybe they're reducing support for iPhone 4s as it's getting old.

If you really want to keep supporting the iPhone 4s, I'd suggest to use iPhone 6 sized images in the 2x slot, and then use the following method to load your images:

+(UIImage *)loadImageNamed:(NSString *)imageName
{
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    CGFloat screenHeight = MAX(screenSize.width, screenSize.height);
    CGFloat const IPHONE_4_SCREEN_HEIGHT = 480;
    UIImage *image = [UIImage imageNamed:imageName];
    if(screenHeight == IPHONE_4_SCREEN_HEIGHT) {
        CGFloat const xScale = .85333333;//x conversion ratio from iPhone 6's 375 pts width screen to iPhone 4's 320 pts width screen
        CGFloat const yScale = .71964018;//y conversion ratio from iPhone 6's 667 pts height screen to iPhone 4's 480 pts height screen
        CGSize newSize = CGSizeMake(xScale * image.size.width, yScale * image.size.height);
        UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);

        [image drawInRect:(CGRect){0, 0, newSize}];
        UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return resizedImage;
    }
    return image;
}

Resizing a big image (iPhone 6) to a smaller one (iPhone 4s) doesn't lose much quality even if the aspect ration is not the same.


Edit:

This is Apple Relations answer to my bug report:

There are no plans to address this based on the following:

We introduced size classes in IB. As such, we want developers to use an XIB with an image view that controls how an image is loaded and displayed. In the event that they absolutely must provided pixel perfect images for all possible screen sizes, then they need to do something like what you suggested and determine the specific resources to load themselves.

We are now closing this report.

If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.

Please be sure to regularly check new Apple releases for any updates that might affect this issue.

添加640 * 1136的图像,因为ip6稍微与ip5成正比,而不是ip4;对于iPhone 6,也有@ 3x选项

You can't add @2x image to your assets and hope it will fit all your sizes. Backgrounds for eg. iP4 and iP5 are just different so you have to use 2 assets regular/@2x for iP4 and regular/@2/@3 for iP5/6 since they have same ratio (universal case).

Other way is set @2x and R4 but there is nothing like @ 2x and @2x retina because it would be the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM