问题
So some iPad in the future is probably going to have Retina Display. And Apple is most likely going to stick to the @2x paradigm. I've been expecting this for awhile and so I already have @2x artwork for iPad in my apps; some are already in the app store.
My question is this: Will I need to recompile and/or resubmit apps to use said artwork when this mythical iPad is released for it to take advantage of these files? Or is this something baked into the OS itself and it should just automagically use them?
(Since the same thing happened before, what happened w/ apps released under the pre-iPhone-4 SDKs that happened to have the right artwork? Did they just work?)
回答1:
I experimented with a retina iPad today, and here's what seems to happen:
- If an app is compiled with a reasonably recent Xcode (probably 4.2+), @2x images are used, just like when the iPhone 4 came out.
- If an app was compiled with Xcode 3, @2x images are not used, even if present. (e.g. in an iphone-4-capable hybrid app.)
(We have a number of XCode-3 based projects, many of which are hybrid for the retina iPhone. None of them used the @2x graphics on the new ipad. When I compiled a test project in both Xcode 3 and Xcode 4, the 4 build used the retina resource and the 3 build did not. Further experiments showed that the difference is compiled into the executable itself, so it's not just a info.plist tweak like I was hoping.)
[eta.: my hypothesis is that compiling with an earlier SDK links you against a different version of UIKit at runtime. Strange differences in behavior as I update our code seem to bear this out. If anyone knows the incantation to know for sure, please comment.]
[edited to add, again: there's some nib difference as well. An old project opened in xcode 4 would not use the @2x graphics until I re-saved my MainWindow.nib; then it did throughout, with no other changes. I suspect a hidden property of the UIWindow object.]
回答2:
What I've found when building with XCode 4.2 (iOS SDK 5.0) running on Snow Leopard is the following:
Images loaded programmatically using [UIImage imagedNamed:] in your code will properly load retina @2x images on the retina iPad.
Images specified on buttons and views in Interface Builder XIB files usually do NOT properly load the @2x retina images.
The workaround I discovered was to force UIImage to cache each of the images referenced in your XIB by using [UIImage imagedNamed:] calls in your view controller's (or appropriate) initWithNibName:(NSString *) bundle:(NSBundle *). The programmatic method does a good @2x load and the system caches it, which the XIB loading mechanism ends up referencing, yielding retina images. For example:
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Doing this to precache proper retina versions, because older xcode nibs aren't loading them correctly on retina iPads with XCode 4.2 builds
[UIImage imageNamed:@"my_button.png"];
[UIImage imageNamed:@"my_other_button.png"];
}
return self;
}
I assume that building with XCode 4.3 (SDK 5.1) works correctly with XIBs, but I was not prepared to upgrade to Lion just to use that version of XCode.
回答3:
I assume this will just work on the device. It is my understanding that [UIImage imageNamed:] looks for the @2x if the device supports it. So it seems built into iOS. This is purely just a guess.
来源:https://stackoverflow.com/questions/9371780/ipad-3-retina-display-2x-images-and-apps-already-in-the-store