Question

I'm trying to write an iPhone app that, when launched, a launch image appears and then takes 2.5 seconds to blur. Once the blur effect is complete, that is when I want the rest of the UI to appear.

I was going to use the following code to blur the image:

[UIView transitionWithView:self.view duration:2.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    self.backgroundImage.image = [UIImage imageNamed:@"640 x 960 Blur10_iOS7@2x.png"];
} completion:^(BOOL finished) {

}];

BackgoundImage is initialized with the regular view of the image and it takes 2.5 seconds to transition to the blur10 view of the image. However, when I run this code from the didViewLoad method, the application opens with the already blurred view of the image and doesn't show the animation. If I run the code from a button press, it works perfectly.

Was it helpful?

Solution

You should put it in:

- (void) viewDidAppear:(BOOL)animated {
    // put stuff here
}

That way, it won't run until the view is visible.

Or, you could prep it in viewWillAppear and start the fade in viewDidAppear.

- (void) viewWillAppear:(BOOL)animated {
    // view is about to appear, set up your blur
} 

- (void) viewDidAppear:(BOOL)animated {
    // view has appeared, start your blur.
}

OTHER TIPS

Blurring an image is an expensive operation. Making an animation that blurs over time is even more expensive and probably won't run as you expect.

You'd be better of creating a number of different images all with different amounts of blur and then animating them in a UIImageView using animationImages and startAnimating.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top