nicklockwood / FXBlurView

[DEPRECATED]
Other
4.94k stars 713 forks source link

Animate blur doesn't seem to be working? iOS 8 GM #80

Open brandonscript opened 9 years ago

brandonscript commented 9 years ago

Not really sure what I'm doing wrong, but no matter what I do, the animation never fires - it just blurs instantly. Code looks like this:

_blurEffectView = [[FXBlurView alloc] initWithFrame:self.superview.bounds];
_blurEffectView.tintColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1];
[self.superview insertSubview:_blurEffectView belowSubview:self];
[FXBlurView animateWithDuration:0.5 animations:^{
    _blurEffectView.blurRadius = 30;
}];
roycable commented 9 years ago

I've had a quick look at the AnimatedBlurExample and ViewController.m uses UIView for the animation.

Eg.

[UIView animateWithDuration:0.5 animations:^{
    self.blurView.blurRadius = 40;
}];

(you're using FXBlurView animateWithDuration: ...)

brandonscript commented 9 years ago

Oh, yeah, @roycable it doesn't make a difference one way or the other. I had just tried to see if calling the method on the subclass would make a difference.

nicklockwood commented 9 years ago

It's because you are calling the animation immediately after inserting the subview. This is a known bug/feature in Core Animation that animations don't work if they are applied to a view before it has appeared on screen.

The workaround is to delay your animation by a single frame, which you can do like this:

_blurEffectView = [[FXBlurView alloc] initWithFrame:self.superview.bounds];
_blurEffectView.tintColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1];
[self.superview insertSubview:_blurEffectView belowSubview:self];
dispatch_async(dispatch_get_main_queue(), ^{
    [UIView animateWithDuration:0.5 animations:^{
        _blurEffectView.blurRadius = 30;
    }];
})

Yeah, it's a bit hacky, but hey, Objective-C ;-)

brandonscript commented 9 years ago

Hrm.. goofy, and it seems to work (albeit really choppy) when going from say, radius=30 to radius=5. But going from no blur to 30, it's still instant. Will play around some more - thanks for the tip!

msmobileapps commented 9 years ago

Grabbing main queue sticks my entire UI

mitchellporter commented 9 years ago

The solution that @nicklockwood posted technically works for me but it looks terrible. It is very glitchy/choppy looking. Will report back if I find a way to smooth out the animation of blurRadius.

datwelk commented 8 years ago

@mitchellporter I'm seeing the same issue. Did you end up finding a smoother way?

mitchellporter commented 8 years ago

@datwelk Nope I never found a solution. I ended up ditching the blur effect all together.