08-01-2009, 11:06 AM
#1 (permalink )
Registered Member
Join Date: May 2009
Posts: 28
display animation but get black square?
Hi, Once again another problem has reared its ugly head! I created a basic animation using a UIImageView and wanted to expand on that by making the code more reusable as I want multiples of that animation displayed on the screen
My idea was to create a UIView class called explosionView.m and .h and write the UIImageView animation code there.
This is the init code within the explosionView.m UIView object file:
Code:
- (id)init {
UIImage *image = [UIImage imageNamed:@"RGB0001.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
aExplosionView = [[UIImageView alloc] initWithFrame:frame];
[image release];
self.opaque = NO;
aExplosionView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"RGB0001.png"],
[UIImage imageNamed:@"RGB0002.png"],
[UIImage imageNamed:@"RGB0003.png"],
[UIImage imageNamed:@"RGB0004.png"],
[UIImage imageNamed:@"RGB0005.png"],
[UIImage imageNamed:@"RGB0006.png"],
[UIImage imageNamed:@"RGB0007.png"],
[UIImage imageNamed:@"RGB0008.png"],
[UIImage imageNamed:@"RGB0009.png"],
[UIImage imageNamed:@"RGB0010.png"],
[UIImage imageNamed:@"RGB0011.png"],
[UIImage imageNamed:@"RGB0012.png"],
[UIImage imageNamed:@"RGB0013.png"],
[UIImage imageNamed:@"RGB0014.png"],
[UIImage imageNamed:@"RGB0015.png"],
nil];
aExplosionView.animationRepeatCount = 1;
aExplosionView.animationDuration = 1;
aExplosionView.center = CGPointMake(0, 0);
[aExplosionView startAnimating];
return self;
}
and in my mainViewController.m I do this to create an instance of the explosionView class in viewDidLoad:
Code:
UIImage *image = [UIImage imageNamed:@"RGB0001.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
explosionView *explo = [[explosionView alloc] initWithFrame:frame];
[image release];
explo.center = CGPointMake(100, 100);
[self.view addSubview:explo];
I have done this before with UIImages for non-animation images - but when I tried with this animating UIImageView, a black square where my animation should be displayed is displayed. No crash, no nothing. Just a black square. Not terribly useful!
Anyone know what's happening?
Thanks
Jetwilson
08-02-2009, 05:47 AM
#2 (permalink )
Registered Member
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
Try taking out the explo.center = CGPointMake(100, 100); line.
08-02-2009, 03:19 PM
#3 (permalink )
Registered Member
Join Date: May 2009
Posts: 28
Quote:
Originally Posted by
kelvinkao
Try taking out the explo.center = CGPointMake(100, 100); line.
That makes no differance. The black square just appears at 0, 0.
I don't completely understand why that would have worked anyway.
03-16-2010, 03:53 AM
#4 (permalink )
Registered Member
Join Date: Jun 2009
Posts: 259
I have the same problem:
myUIImageView.animationImages
doesnt work in instances of an UIView.
did you (anyone?) come up with a solution?
EDIT:
Really strange. I believe I'm missing something fundamental here...
When I use an UIView the "normal" way, the animation works fine and the animation array is filled correctly:
Code:
// after creating an myAnimationImages-array
myUIImageView.animationImages = myAnimationImages;
NSLog(@"animation: %@", myUIImageView.animationImages);
/* output:
animation: (
<UIImage: 0xd3ccc0>,
<UIImage: 0xd39820>,
<UIImage: 0xd3b530>,
<UIImage: 0xd398d0>,
)
When I do the same in my UIView-Instance the output is:
any help is appreciated.
EDIT II:
oh. and I may add, that setImage using the same array of images works perfectly fine:
Code:
[myUIImageView setImage:[UIImage imageWithContentsOfFile:[myAnimationImages objectAtIndex: 1]]];
EDIT III:
okay. i'm using a NSTimer to shoot off a sequence of "setImage" now.
Last edited by finefin; 03-16-2010 at 09:07 AM .
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 262
22 members and 240 guests
ADY , AragornSG , bookesp , chillyh , dacapo , Dani77 , Davey555 , Desert Diva , Dominus , glenn_sayers , HemiMG , JasonR , LEARN2MAKE , M.A.S. , marshusensei , mer10 , nobre84 , Oral B , prchn4christ , Raggou , Rudy , themathminister
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp