today I decided to make my own animations instead of using UINavigationController
's ones; so I've designed an animation (afterwards pseudocode), however I stumbled when I started to write the code. I've thought it will be good if I can make a class hence I can share it.
Let me explain it with words at first, there are two view controllers, when pushing the latter view controller former view controller's view should be blurred, then latter's blurred image should come into. Former's blurred image should go hidden and finally the blur of the latter image should resolve to show the latter view controller properly.
I've got the former VC's image properly with [UIImage convertViewToImage]
, however I couldn't get the latter VC's image.
I have to push new VC if I want to get snapshot of it with same logic, but you may understand it doesn't seem optimized and practical.
Let me show the code:
- (void)makeLastBackgroundBlur
{
self.lastBackgroundView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIImage *image = [[UIImage convertViewToImage] applyBlurWithRadius:5.0
tintColor:[UIColor colorWithWhite:0.2
alpha:0.7]
saturationDeltaFactor:1.8
maskImage:nil];
self.lastBackgroundView.image = image;
self.lastBackgroundView.alpha = 0;
[self addSubview:self.lastBackgroundView];
}
- (void)makeNextBackgroundBlur
{
self.nextBackgroundView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
// The part I couldn't do
UIImage *image = [theImageOfTheLatterVC applyBlurWithRadius:5.0
tintColor:[UIColor colorWithWhite:0.2
alpha:0.7]
saturationDeltaFactor:1.8
maskImage:nil];
self.nextBackgroundView.image = image;
self.nextBackgroundView.alpha = 1;
self.nextBackgroundView.hidden = YES;
[self addSubview:self.nextBackgroundView];
}
- (void)invokeAnimation
{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// Invoke the blurred background with animation
[UIView animateWithDuration:(self.duration / 2.00)
animations:^{
self.lastBackgroundView.alpha = 1.0f;
}
completion:^(BOOL finished){
self.nextBackgroundView.hidden = NO;
[UIView animateWithDuration:(self.duration / 2.00)
animations:^{
self.nextBackgroundView.alpha = 0;
} completion:^(BOOL finished){
self.lastBackgroundView = nil;
}];
}];
}