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 Build a Simple iPhone App (iOS7) Animating and Intercepting Events Image Based Animation

Crystal ball app only moving with Animation when you shake it. I have no idea why?

Here is the video http://teamtreehouse.com/library/build-a-simple-iphone-app-ios7-2/animating-and-intercepting-events/image-based-animation

//and here is my code

import "THViewController.h"

import "THCrystalBall.h"

@interface THViewController ()

@end

@implementation THViewController

  • (void)viewDidLoad { [super viewDidLoad]; self.crystalBall = [[THCrystalBall alloc] init];

    self.backgroundImageView.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"CB00001"], [UIImage imageNamed:@"CB00002"], [UIImage imageNamed:@"CB00003"], [UIImage imageNamed:@"CB00004"], [UIImage imageNamed:@"CB00005"],

//alot of typing ....im going to skip down...

                                            [UIImage imageNamed:@"CB00059"],
                                            [UIImage imageNamed:@"CB00060"],nil];

self.backgroundImageView.animationDuration = 2.5f;
self.backgroundImageView.animationRepeatCount = 1;

}

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.

}

pragma mark - Prediction

-(void) makePrediction; { [self.backgroundImageView startAnimating]; self.predictionLabel.text = [self.crystalBall randomPrediction]; }

pragma mark - Motion Events

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { self.predictionLabel.text = nil; }

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion == UIEventSubtypeMotionShake) { [self makePrediction]; } }

-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"motion cancelled"); }

2 Answers

Stone Preston
Stone Preston
42,016 Points

so are you saying its not animating when you tap the screen? if so can you post your code for the touches please. you need to make sure you call the makePrediction method inside the touches ended method:

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

    [self makePrediction];

}

wow your awesome. That one thing made it work. Thank you so much! What video did he say do this part in because I don't remember that!