2012-05-02 7 views
1

キャッシュまたはドキュメントに保存されているイメージのデバイス修飾子〜ipad、〜iphone、@ 2xを利用する方法はありますか?限り、私はそれがファイルがメインバンドルに格納されている場合にのみ動作することを伝えることができます。ドキュメントまたはキャッシュフォルダ内のiOSファイル名デバイス修飾子(〜ipad、〜iphone)の使用

NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *cachePath = ([cachePaths count] > 0) ? [cachePaths objectAtIndex:0] : nil; 
NSString *cacheResourcesPath = [cachePath stringByAppendingPathComponent:@"Resources"]; 

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil; 
NSString *documentsResourcesPath = [documentPath stringByAppendingPathComponent:@"Resources"]; 

    // SUCCESS (/caches/resources) 
    UIImage *image = [UIImage imageWithContentsOfFile:[cacheResourcesPath stringByAppendingPathComponent:@"image~ipad.png"]]; 

    // FAIL (/caches/resources) 
    UIImage *image = [UIImage imageWithContentsOfFile:[cacheResourcesPath stringByAppendingPathComponent:@"image.png"]]; 

    // SUCCESS (/documents) 
    UIImage *image = [UIImage imageWithContentsOfFile:[documentsResourcesPath stringByAppendingPathComponent:@"image~ipad.png"]]; 

    // FAIL (/documents) 
    UIImage *image = [UIImage imageWithContentsOfFile:[documentsResourcesPath stringByAppendingPathComponent:@"image.png"]]; 

    // SUCCESS (main bundle) 
    UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]; 

    // SUCCESS (main bundle) 
    UIImage *image = [UIImage imageNamed:@"image"]; 

答えて

0

私は確かにimageWithContentsOfFile:メソッドがファイル名を解析しないと確信しています。バンドルの一部ではない@ 2xイメージを読み込もうとしたときに、同じ問題がiPhoneに戻ってきました。最後に、スケールを適切に設定できるように、initWithCGImage:scale:orientation:を使用しなければなりませんでした。それに基づいて、接尾辞~ipadを処理できれば驚くでしょう。

+0

上記のように見えます。私は、キャッシュディレクトリのファイルのファイル名(〜ipad、〜iphone、@ 2x〜ipad、@ 2x〜iphone)について自分で調べることになりました。 –

関連する問題