Device os在应用程序进入后台时创建快照屏幕图像,这里是您可以在应用程序“AppData/Library/Caches/Snapshots /”的沙箱中找到的路径。
这是一种技巧,您可以防止在应用程序启动时显示应用程序的最后一个屏幕。
// Create subclass of UIImageView
@interface SnapShotImageView :UIImageView
@end
@implementation SnapShotImageView :UIImageView
@end
// Create function in appdelegate.m
- (void)createSnapshotWhileApplicationGoesInBackground{
NSString *splashImg = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
splashImg= @"Default~ipad.png";
}
else {
splashImg= @"Default~iphone.png";
}
UIWindow *win = [[UIApplication sharedApplication] keyWindow];
SnapShotImageView *splash = [[SnapShotImageView alloc] initWithImage:[UIImage imageNamed:splashImg]];
splash.frame = self.window.bounds;
[win addSubview:splash];
}
- (void)removeSnapshotFromWindow{
UIWindow *win = [[UIApplication sharedApplication] keyWindow];
if ([[win subviews] count] > 1) {
[NSThread sleepForTimeInterval:0.5];
NSArray *array = [win subviews];
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[SnapShotImageView class]]) {
[obj removeFromSuperview];
}
}];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self removeSnapshotFromWindow];
}
//Call this function Application delegate method this way..
- (void)applicationDidEnterBackground:(UIApplication *)application {
[self createSnapshotWhileApplicationGoesInBackground];
}
- (void)applicationWillEnterForeground:(UIApplication *)application{
[self removeSnapshotFromWindow];
}
- (void)applicationDidBecomeActive:(UIApplication *)application{
[self removeSnapshotFromWindow];
}
这里我们创建启动画面的快照..只是在窗口中添加启动画面。当应用程序就会在后台
和removeing快照时,应用进来前景
请看看我的编辑 – 2012-03-04 14:57:19