Yes, you can!
Now you are able to change the snapshot of your app while is in background!
An example here:
How to?
Make a new project, and in your AppDelegate.m, consider the system methods:
- (void)applicationWillResignActive:(UIApplication *)application {
// to add your background controller
[self applySnapshot];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// to remove your background controller
[self removeSnapshot];
}
Next, add in applicationWillResignActive method the “applySnapshot” and then call “removeSnapshot” to remove it in applicationDidBecomeActive.
Method applySnapshot, make a screenshot of your screen and next apply to the captured image, the CIGaussianBlur filter to show you the blur effect.
At the bottom of the method there is an image array animated, just to show you the potentiality!
-(void)applySnapshot {
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage];
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"];
[gaussianBlurFilter setValue:[NSNumber numberWithFloat: 2] forKey: @"inputRadius"];
CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"];
viewImage = [[UIImage alloc] initWithCIImage:resultImage];
UIImageView *newView = [[UIImageView alloc] initWithFrame:rect];
newView.image = viewImage;
newView.tag = 1234;
newView.alpha = 0;
UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
imgv.animationImages = @[
[UIImage imageNamed:@"1"],
[UIImage imageNamed:@"2"],
[UIImage imageNamed:@"3"]
];
imgv.animationDuration = 3;
[imgv startAnimating];
[newView addSubview:imgv];
[self.window addSubview:newView];
[self.window bringSubviewToFront:newView];
[UIView animateWithDuration:0.25 animations:^{
newView.alpha = 1;
}];
}
- (void) removeSnapshot {
UIView *colourView = [self.window viewWithTag:1234];
[UIView animateWithDuration:0.25 animations:^{
colourView.alpha = 0;
} completion:^(BOOL finished) {
[colourView removeFromSuperview];
}];
}
Have fun!
thanks.