Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-05-2010, 10:44 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Age: 29
Posts: 9
Smikey is on a distinguished road
Default Subclassing UIImageView - nothing appears?

Hi everyone,

I'm trying to subclass UIImageView in order to create an instance of the subclass which plays different animations, depending on a variable I send it. My initial code (before subclassing) for playing a specific 2 frame animation looked like this (and worked fine). 'bubbleAnimationTemp' is just a UIImageView object I declared in the header:

Code:
UIImage *animImage1 = [UIImage imageNamed:@"HappyAnim1.png"];
    UIImage *animImage2 = [UIImage imageNamed:@"HappyAnim2.png"];
    NSArray *images = [[NSArray alloc] initWithObjects:animImage1, animImage2, nil];
    bubbleAnimationTemp.animationImages = images;
    [images release];
    bubbleAnimationTemp.animationDuration = 0.5;
    bubbleAnimationTemp.animationRepeatCount = 5;
    [bubbleAnimationTemp startAnimating];
So then I tried subclassing UIImageView like so:

Code:
#import <UIKit/UIKit.h>
#import "Interaction.h"

@interface BubbleAnimation : UIImageView {
    UIImage *emotAnim1;
    UIImage *emotAnim2;
}

@property (nonatomic, retain) UIImage *emotAnim1;
@property (nonatomic, retain) UIImage *emotAnim2;

- (BubbleAnimation *)initWithMood:(NSString *)mood;
@end

#import "BubbleAnimation.h"

@implementation BubbleAnimation

@synthesize emotAnim1;
@synthesize emotAnim2;

- (BubbleAnimation *)initWithMood:(NSString *)mood {
    if (self = [super init]) {
        NSLog(@"Mood: %@", mood);
        if ([mood isEqualToString:kGood]) {
            emotAnim1 = [[UIImage alloc] initWithContentsOfFile:([[NSBundle mainBundle] pathForResource:@"HappyAnim1" ofType:@"png"])];
            emotAnim2 = [[UIImage alloc] initWithContentsOfFile:([[NSBundle mainBundle] pathForResource:@"HappyAnim2" ofType:@"png"])];
            //emotAnim1 = [UIImage imageNamed:@"HappyAnim1.png"];
            //emotAnim2 = [UIImage imageNamed:@"HappyAnim2.png"];
        }
        else if ([mood isEqualToString:kNeutral]) {
            emotAnim1 = [UIImage imageNamed:@"NeutralAnim1.png"];
            emotAnim2 = [UIImage imageNamed:@"NeutralAnim2.png"];
        }
        else {
            emotAnim1 = [UIImage imageNamed:@"SadAnim1.png"];
            emotAnim2 = [UIImage imageNamed:@"SadAnim2.png"];
        }
        NSArray *images = [[NSArray alloc] initWithObjects:emotAnim1, emotAnim2, nil];
        self.animationImages = images;
        [images release];
    }
    return self;
}
As you can see, I tried two different approaches for creating the UIImages to add to the UIImageView. But the problem I'm having is that nothing shows up when the animation plays.

I also tried simply copying the code from the first method into this subclass, so the process is essentially the same, but still nothing appears.

I've checked the documentation for notes on subclassing UIImageView but there doesn't seem to be anything I'm missing. I've made sure to change the 'UIImageView' object I placed in Interface Builder into a 'BubbleAnimation' object, so it's not that.

By the way, this is how I'm calling the animation to be played:

Code:
bubbleAnimation = [[BubbleAnimation alloc] initWithMood:charcter.mood]; 
bubbleAnimation.animationDuration = 0.5; 
bubbleAnimation.animationRepeatCount = 5; 
[bubbleAnimation startAnimating];
Any help as to why nothing appears would be very much appreciated. Thanks as always!

Michael
Smikey is offline   Reply With Quote
Old 01-20-2011, 10:09 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

I dont see anywhere that you set the frame in your subclass. Maybe a call to [super initWithFrame:] would be better than just a [super init] ?
smithdale87 is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, subclassing, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 330
6 members and 324 guests
anothermine, Chickenrig, givensur, michaelhansen, PixelInteractive, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0