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
Stone Preston
42,016 PointsCrystal Ball not animating
Trying to get the animations to work for the crystal ball app and cant get them to start animating. Ive added all the images, defined the imageView property, sythesized it. changed the references to imageView to self.Imageview, added the animation images to the array, set the duration and repeat counts, and called the startAnimating method in the makePrediction array. For some reason the animation does not start. I cant seem to figure out. Amit Bijlani
//
// ViewController.m
// Crystal Ball
//
// Created by Stone Preston on 8/29/13.
// Copyright (c) 2013 Stone Preston. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize predictionArray;
@synthesize imageView;
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"background.png"];
self.imageView = [[UIImageView alloc] initWithImage: image];
[self.view insertSubview:self.imageView atIndex:0];
self.imageView.animationImages = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"cball00001"],
[UIImage imageNamed:@"cball00002"],
[UIImage imageNamed:@"cball00003"],
[UIImage imageNamed:@"cball00004"],
[UIImage imageNamed:@"cball00005"],
[UIImage imageNamed:@"cball00006"],
[UIImage imageNamed:@"cball00007"],
[UIImage imageNamed:@"cball00008"],
[UIImage imageNamed:@"cball00009"],
[UIImage imageNamed:@"cball00010"],
[UIImage imageNamed:@"cball00011"],
[UIImage imageNamed:@"cball00012"],
[UIImage imageNamed:@"cball00013"],
[UIImage imageNamed:@"cball00014"],
[UIImage imageNamed:@"cball00015"],
[UIImage imageNamed:@"cball00017"],
[UIImage imageNamed:@"cball00018"],
[UIImage imageNamed:@"cball00019"],
[UIImage imageNamed:@"cball00020"],
[UIImage imageNamed:@"cball00021"],
[UIImage imageNamed:@"cball00022"],
[UIImage imageNamed:@"cball00023"],
[UIImage imageNamed:@"cball00024"], nil];
self.imageView.animationDuration = 1.0;
self.imageView.animationRepeatCount = 1;
// Do any additional setup after loading the view, typically from a nib.
self.predictionArray = [[NSArray alloc] initWithObjects: @"It is Certain",
@"It is decidely so",
@"My reply is no",
@"Unable to answer now",
nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)makePrediction {
NSUInteger index = arc4random_uniform(self.predictionArray.count);
self.predictionLabel.text = [self.predictionArray objectAtIndex:index];
[self.imageView startAnimating];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
self.predictionLabel.text = @"";
}
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
[self makePrediction];
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
}
NSLog(@"Motion Cancled");
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.predictionLabel.text = @"";
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self makePrediction];
}
@end
1 Answer
Amit Bijlani
Treehouse Guest TeacherPlease make sure that you don't have an image view specified in your storyboard. If you do then it could be blocking the image view you created programmatically in the viewDidLoad method.
Stone Preston
42,016 PointsStone Preston
42,016 Pointsthat was it! I must have forgotten to delete it the first time after we created the image programmatically. Nice catch there. Thanks again. Works like a charm now