Xcode - animating UIVisualEffectView

I have a problem animating a VisualEffetView. Here is the code where I am declaring it.

UIBlurEffect* blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
effectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
effectView.frame = self.bounds;
self.layer.borderWidth = 1;
[self addSubview:effectView];

      

When I animate a supervisor to grow it, the visual effect follows the animation of the supervisor, but when I want to decrease it, the visual effect disappears instantly, which makes the result very ugly ^^ Here is the code in which I animate the supervisor (called recherche here)

[UIView animateWithDuration:0.3f
                          delay:0.0f
                        options:UIViewAnimationOptionTransitionNone
                     animations:^{
                         CGRect f = recherche.frame;
                         f.size.height = 0;
                         [recherche setFrame:f];
                     }
                     completion:^(BOOL finished){
                         [recherche removeFromSuperview];
                         recherche = nil;
                     }];

      

This is what I have when I make the recherche disappear. The white square seems to be an effect because the color changes if I change the UIBlurEffectStyle. But there is no blur effect x) Screenshot

+3


source to share


1 answer


From the understanding above, I figure out that you just need to reset the height of effect view to achieve what you want.

Added code in animation block:



Check it out and let me know, this completely fills your expectation.

[UIView animateWithDuration:0.3f
                      delay:0.0f
                    options:UIViewAnimationOptionTransitionNone
                 animations:^{
     CGRect f = recherche.frame;
     f.size.height = 0;
     [recherche setFrame:f];

     // Add this lines
     CGRect effectViewFrame = effectView.frame;
     effectView.size.height = 0;
     effectView.frame = effectViewFrame;

 }
 completion:^(BOOL finished){
     [recherche removeFromSuperview];
     recherche = nil;
 }];

      

0


source







All Articles