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

Animating and Intercepting Events - Extra Credit

I am really curious about the extra credit question, so I decide to do it just to get more practice and understanding of Objective-C programing. So, when I run program it works, I am not really understanding how it is working though, cause right now it animates the text down, but doesn't animate back up. It just pops back to the center of the screen, you don't see it move back up at all. Also, I have no idea how to go about the using the tap count property for the second part of the extra credit. Anyways, here is my code, any help would be great!

- (void) makePrediction {
    [self.backgroundImageView startAnimating];
    self.predictionLabel.text = [self.crystalBall randomPrediction];
    self.predictionLabel.textColor = [self.crystalBall randomColor];
    AudioServicesPlaySystemSound(soundEffect);
    [UIView animateWithDuration:1.0 animations:^{
        self.predictionLabel.frame = CGRectMake(36, 329, 249, 145);
    } completion:^(BOOL finished) {
        self.predictionLabel.frame = CGRectMake(36, 184, 249, 145);
    }];
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self.predictionLabel.text = nil;
    [self makePrediction];
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

}

1 Answer

ok so the reason it's doing that is because in the completion you say "Hey when you're done moving nice and animated to your new bounds instantly relocated to the completion bounds" the way to solve this would be to say something like

- (void) makePrediction {
    [self.backgroundImageView startAnimating];
    self.predictionLabel.text = [self.crystalBall randomPrediction];
    self.predictionLabel.textColor = [self.crystalBall randomColor];
    AudioServicesPlaySystemSound(soundEffect);
    [UIView animateWithDuration:1.0 animations:^{
        self.predictionLabel.frame = CGRectMake(36, 329, 249, 145);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration: 1.0 /* next it takes a block but i don't remember what it is*/ block ^{
          self.predictionLabel.frame = CGRectMake(36, 184, 249, 145);
}
    }];

}

this will make it animate over 1 secound to the new bounds making it animate up the in the completion block we animate it back down

now, I've never believed in giving the answer so i'll lead you in the right direction for the secound part, simply google tap gesture recognizers and specifically double-tap recognizer (at least I'm pretty sure that's one) the way you implement these are by doing a UIDoubleTapGesturRecognizer then name it and allocate and initialize it (so make a new one) then add it to the object so the view. it would look something like this.

UIDoubleTapGestureRognizer *doubleTap = [[UIDoubleTapGestureRecognizer alloc] initWithTarget: self action: @selector(someMethodThatHandlesGoal) /* again there is probably more but you can google how to use double tap recognizers */];

[self.view addRecognizer: doubleTap];

//then make the method for someMethodThatHandlesGoal and it would be a void so ill give you a start

-(void)someMethodThatHandlesGoal{
    ///TODO: make your things to achieve goal number 2 that you didn't know
}

anyways this is alot to take in so I'd be happy to help explain.

Happy hacking, Kai.