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

Keith Selvin
PLUS
Keith Selvin
Courses Plus Student 630 Points

animating crystal ball

I have the exact same frames per second as the video says but it moves with alot of lag, it also stops in the middle of the array of images

3 Answers

Brett Kim
Brett Kim
11,576 Points

That sounds like a problem related with your computer. What kind of computer do you use?

Keith Selvin
PLUS
Keith Selvin
Courses Plus Student 630 Points

A Macbook Pro purchased in 2011 running Maverick OSX

Brett Kim
Brett Kim
11,576 Points

That should be fine... Can you show me your code?

Keith Selvin
PLUS
Keith Selvin
Courses Plus Student 630 Points

sorry don'd mind the things i commented out just to help myself learn the different ways of doing things

/ KTSViewController.h // CrystalBall // // Created by Keith Selvin on 5/15/14. // Copyright (c) 2014 Keith Selvin. All rights reserved. //

// interface

import <UIKit/UIKit.h>

@class KTSCrystalBall;

@interface KTSViewController : UIViewController

@property (strong, nonatomic) IBOutlet UILabel *predictionLabel; @property (strong, nonatomic) KTSCrystalBall *crystallBall;

//weak: claim no ownership, system can deallocate from memory whenever neccessary

//- (IBAction)buttonPressed; //drag action from storyboard window

  • (void) makePrediction;

@property (strong, nonatomic) IBOutlet UIImageView *backgroundImageView; @end

// // KTSViewController.m // CrystalBall // // Created by Keith Selvin on 5/15/14. // Copyright (c) 2014 Keith Selvin. All rights reserved. //

import "KTSViewController.h"

import "KTSCrystalBall.h"

@interface KTSViewController ()

@end

@implementation KTSViewController

  • (void)viewDidLoad { [super viewDidLoad];

    self.crystallBall = [[KTSCrystalBall alloc] init]; self.backgroundImageView.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"CB00001"], [UIImage imageNamed:@"CB00002"], [UIImage imageNamed:@"CB00003"], [UIImage imageNamed:@"CB00004"], [UIImage imageNamed:@"CB00005"], [UIImage imageNamed:@"CB00006"], [UIImage imageNamed:@"CB00007"], [UIImage imageNamed:@"CB00008"], [UIImage imageNamed:@"CB00009"], [UIImage imageNamed:@"CB00010"], [UIImage imageNamed:@"CB00011"], [UIImage imageNamed:@"C0B0012"], [UIImage imageNamed:@"CB00013"], [UIImage imageNamed:@"CB00014"], [UIImage imageNamed:@"CB00015"], [UIImage imageNamed:@"CB00016"], [UIImage imageNamed:@"CB00017"], [UIImage imageNamed:@"CB00018"], [UIImage imageNamed:@"CB00019"], [UIImage imageNamed:@"CB00020"], [UIImage imageNamed:@"CB00021"], [UIImage imageNamed:@"CB00022"], [UIImage imageNamed:@"CB00023"], [UIImage imageNamed:@"CB00024"], [UIImage imageNamed:@"CB00025"], [UIImage imageNamed:@"CB00026"], [UIImage imageNamed:@"CB00027"], [UIImage imageNamed:@"CB00028"], [UIImage imageNamed:@"CB00029"], [UIImage imageNamed:@"CB00030"], [UIImage imageNamed:@"CB00031"], [UIImage imageNamed:@"CB00032"], [UIImage imageNamed:@"CB00033"], [UIImage imageNamed:@"CB00034"], [UIImage imageNamed:@"CB00035"], [UIImage imageNamed:@"CB00036"], [UIImage imageNamed:@"CB00037"], [UIImage imageNamed:@"CB00038"], [UIImage imageNamed:@"CB00039"], [UIImage imageNamed:@"CB00040"], [UIImage imageNamed:@"CB00041"], [UIImage imageNamed:@"CB00042"], [UIImage imageNamed:@"CB00043"], [UIImage imageNamed:@"CB00044"], [UIImage imageNamed:@"CB00045"], [UIImage imageNamed:@"CB00046"], [UIImage imageNamed:@"CB00047"], [UIImage imageNamed:@"CB00048"], [UIImage imageNamed:@"CB00049"], [UIImage imageNamed:@"CB00050"], [UIImage imageNamed:@"CB00051"], [UIImage imageNamed:@"CB00052"], [UIImage imageNamed:@"CB00053"], [UIImage imageNamed:@"CB00054"], [UIImage imageNamed:@"CB00055"], [UIImage imageNamed:@"CB00056"], [UIImage imageNamed:@"CB00057"], [UIImage imageNamed:@"CB00058"], [UIImage imageNamed:@"CB00059"], [UIImage imageNamed:@"CB00060"], nil]; self.backgroundImageView.animationDuration = 2.5f; self.backgroundImageView.animationRepeatCount = 1;

    //instead of using view controller // UIImage *backgroundImage = [UIImage imageNamed:@"background"]; //UIImageView *imageView = [[UIImageView alloc] initWithImage: backgroundImage]; //[self.view insertSubview: imageView atIndex:0];

    // Do any additional setup after loading the view, typically from a nib.

}

//- (void) viewDidAppear:(BOOL)animated{ // [super viewDidAppear:animated];

//CGRect frame = self.predictionLabel.frame;     // moves label
//self.predictionLabel.frame = CGRectMake(frame.origin.x, 200, frame.size.width, frame.size.height);

//}

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

  • (IBAction)buttonPressed {

    //allocates space in memory for objects to store

//NSLog(@"Button Pressed"); //NSS log displays text in console

 self.predictionLabel.text = [self.crystallBall randomPrediction];

 //self: instance of viewController
// predictionLabel: name of property, has text method

}

pragma mark - Prediction

  • (void) makePrediction{ [self.backgroundImageView startAnimating]; self.predictionLabel.text = [self.crystallBall 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"); }

pragma mark - Touch Events

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

  • (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self makePrediction]; }

  • (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touches cancelled"); }

@end