Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Nicolas Acosta
Nicolas Acosta
1,587 Points

I need help with some help with an iOS issue please.

I'm on the 'Build a Simple iPhone App' of the iOS Development track.

Here's the link to a screenshot of my Xcode project: https://www.dropbox.com/s/okgx01pxosupc6q/Captura%20de%20pantalla%202014-08-02%2002.03.36.png

In the makePredtion function (Prediction pragma Mark), I want say something like:

_ The text disappears DONE

 self.predictionLabel.text = @" ";

_ The animation DONE

 [self.backgroundImageView startAnimating];

_ When the animation finished, make the prediction. I DON'T KONW IF IT'S OK

 if (self.backgroundImageView animationDidStop:????????????? finished:YES) {
 self.predictionLabel.text = [self.crystalBall randomPrediction];
 }

I need help with the last one

1 Answer

Pierre Thalamy
Pierre Thalamy
4,494 Points

I don't think you can use animationDidStop for this, or at least, not as easily as you want to. If I got you right, what you want to do is:

  1. Hide the label
  2. Animate the UIImageView
  3. Only once the animation is over, have the label's text to reappear.

Here is another way, to do this:

- (void) makePrediction
{
    // Animate the UIImageView
    [self.backgroundImageView startAnimating];
    // Animate the view over 1 second (you may need to tweak the timing to match your needs)    
    [UIView animateWithDuration:1.0f animations:^{
       // Slowly fade out the label 
       self.predictionLabel.alpha = 0;
    } completion:^(BOOL finished){
    // Once fading is over:    
    [UIView animateWithDuration:1.0f animations:^{
            // Update the label's text
            self.predictionLabel.text = [self.crystalBall randomPrediction];   
            // Slowly fade in the label
            self.predictionLabel.alpha = 1;
        }];
    }];
}

The animateWithDuration method will perform the tasks enclosed inside the block with the symbols ^{...} gradually, over the period of time specified as argument. Here it is used to get a nice fading effect.

Let me know if you have any questions.