SORU
17 EYLÜL 2014, ÇARŞAMBA


Nasıl iPhone 6 için boyut belirlemek için özel kenardan kenara görüntü?

Birlikte bir resim bir iPhone uygulaması - örneğin mevcut tüm ekran genişliği bir banner almak istiyorum diyelim. Genişlik 640px my_banner@3x.png 320px, my_banner@2x.png genişlik my_banner.png oluşturmak istiyorumiPhone 6 plus1242px genişliği ile. Ama çözünürlüğüiPhone 6750×1334 piksel. Hala 640px genişliği olan iPhone 4 ve 5 @2x soneki paylaşmaktadır.

Bu nedirönerilen yöntem budurya da biriyi bir yolubir resmi belirtmek için o 750px genişliği için optimize edilmiş dosyaiPhone 6? Öyle görünüyor olamaz asset catalog yapılacak? Programlama yoluyla yapılmalıdır? Var için kullanılan başka bir sonekiPhone 6?

iPhone 4,5,6 screen sizes (Resim http://www.iphoneresolution.com elde)

CEVAP
31 EKİM 2014, Cuma


Bu cevap çok doğru ortam dosyası yükleme ile ilgili olduğunu düşündüğüm yerde, imageView, sınırlamak için nasıl hitap etmek istiyor gibi geliyor bana? Kendi geleceği genişletilebilir benim çözüm bu gibi bir şey olacaktır:

"DeviceSpecificMedia Uİİmage."- (Uİİmage bir kategori) . h

Arayüz:

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, thisDeviceClass) {

    thisDeviceClass_iPhone,
    thisDeviceClass_iPhoneRetina,
    thisDeviceClass_iPhone5,
    thisDeviceClass_iPhone6,
    thisDeviceClass_iPhone6plus,

    // we can add new devices when we become aware of them

    thisDeviceClass_iPad,
    thisDeviceClass_iPadRetina,


    thisDeviceClass_unknown
};

thisDeviceClass currentDeviceClass();

@interface UIImage (DeviceSpecificMedia)

  (instancetype )imageForDeviceWithName:(NSString *)fileName;

@end

Uygulama:

#import "UIImage DeviceSpecificMedia.h"

thisDeviceClass currentDeviceClass() {

    CGFloat greaterPixelDimension = (CGFloat) fmaxf(((float)[[UIScreen mainScreen]bounds].size.height),
                                                    ((float)[[UIScreen mainScreen]bounds].size.width));

    switch ((NSInteger)greaterPixelDimension) {
        case 480:
            return (( [[UIScreen mainScreen]scale] > 1.0) ? thisDeviceClass_iPhoneRetina : thisDeviceClass_iPhone );
            break;
        case 568:
            return thisDeviceClass_iPhone5;
            break;
        case 667:
            return thisDeviceClass_iPhone6;
            break;
        case 736:
            return thisDeviceClass_iPhone6plus;
            break;
        case 1024:
            return (( [[UIScreen mainScreen]scale] > 1.0) ? thisDeviceClass_iPadRetina : thisDeviceClass_iPad );
            break;
        default:
            return thisDeviceClass_unknown;
            break;
    }
}

@implementation UIImage (deviceSpecificMedia)

  (NSString *)magicSuffixForDevice
{
    switch (currentDeviceClass()) {
        case thisDeviceClass_iPhone:
            return @"";
            break;
        case thisDeviceClass_iPhoneRetina:
            return @"@2x";
            break;
        case thisDeviceClass_iPhone5:
            return @"-568h@2x";
            break;
        case thisDeviceClass_iPhone6:
            return @"-667h@2x"; //or some other arbitrary string..
            break;
        case thisDeviceClass_iPhone6plus:
            return @"-736h@3x";
            break;

        case thisDeviceClass_iPad:
            return @"~ipad";
            break;
        case thisDeviceClass_iPadRetina:
            return @"~ipad@2x";
            break;

        case thisDeviceClass_unknown:
        default:
            return @"";
            break;
    }
}

  (instancetype )imageForDeviceWithName:(NSString *)fileName
{
    UIImage *result = nil;
    NSString *nameWithSuffix = [fileName stringByAppendingString:[UIImage magicSuffixForDevice]];

    result = [UIImage imageNamed:nameWithSuffix];
    if (!result) {
        result = [UIImage imageNamed:fileName];
    }
    return result;
}

@end

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Dirty Loops

    Dirty Loops

    21 Mayıs 2007
  • kruno j

    kruno j

    6 Mayıs 2007
  • TV nEW

    TV nEW

    25 AĞUSTOS 2012