How can I change the blur of a UIVisualEffectView when dragging and dropping in iOS?

I am currently using UIVisualEffectView to blur the image.

I have a UIScrollView. When I click on scrollView, in my "scrollViewDidScroll" method, I change the alpha of the UIVisualEffectView. The current behavior of this is that the blur radius changes smoothly when I drag in the view.

The problem, of course, I should not do this. Receive alerts about changing the alpha value of a UIVisualEffectView.

I saw people say to make a smooth blur transition using animation, like this here: How to output and display a UIVisualEffectView and / or UIBlurEffect? A.

However, I did not see anything that allowed me to do this during, say, a pan-gesture or something like that. I mean, if I set up the animation with a temporary sum, everything is fine. But do it while dragging and dropping?

+6
source share
1 answer

There is a way :)

As you noticed, you can animate the nil effect to an effect similar to UIBlurEffectStyleDark , so if we add an animation and then pause the animation of the layer, we can control the progress of the effect by adjusting the timeOffset layer

 - (void) setupBlur { // Setup the blur to start with no effect self.blurredEffectView = [[UIVisualEffectView alloc] initWithEffect:nil]; // Add animation to desired blur effect [UIView animateWithDuration:1.0 animations:^{ [self.blurredEffectView setEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]]; }]; // Pause layer animations self.blurredEffectView.layer.speed = 0; } 

Adjust the blur between 0.0 and 1.0 (animation duration):

 - (void) adjustBlur:(CGFloat)blurIntensity { self.blurredEffectView.layer.timeOffset = blurIntensity; } 
  • Note: this will not work on iOS 8, where UIBlurEffect animations are not supported.
+7
source

All Articles