Sam
Sam

Reputation: 1230

iOS: Transition animation with UIBlurEffect?

I'm using the UIBlurEffect implemented in iOS 8 to blur the screen easily. However, I'm experiencing a problem since I can't figure out how to make this blur effect into an animation rather than a instant effect.

I tried using this but it didn't work:

[UIView animateWithDuration:3 animations:^
{
    visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    visualEffectView.frame = self.view.frame;
    [self.view addSubview:visualEffectView];
}];

While it did display the effect, it didn't animate throughout the 3 seconds.

Upvotes: 1

Views: 1712

Answers (2)

Dimitar Stefanovski
Dimitar Stefanovski

Reputation: 889

First you are defining UIVisualEffectView() and define its frame and after that you can animate the blurView with effect:

let blurView = UIVisualEffectView()
blurView.frame = self.view.bounds

UIView.animate(withDuration: 0.5) {
   blurView.effect = UIBlurEffect(style: .light)
}

Upvotes: 0

matt
matt

Reputation: 534914

You are not seeing any animation because you didn't do anything that animates. UIView animation relies on the use of animatable properties of an existing view. You aren't animating any properties: you are merely calling addSubview:.

Upvotes: 2

Related Questions