Reputation: 730
Just started Objective-C - trying to make 4 images fadein/fadeout continuously.
The code below is not working. I know the button is working because the text of my label changes, however no pictures animate. No errors either ...
h.
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UIImageView *viewer;
}
@property (nonatomic, retain) UIImageView *viewer;
@property (nonatomic,retain) IBOutlet UILabel *label1;
@end
m.
-(IBAction)startImageViewAnimation
{
label1.text = @"CHECK?";
NSArray *animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"backgrounds_app1-01.png"],
[UIImage imageNamed:@"backgrounds_app2-02.png"],
[UIImage imageNamed:@"backgrounds_app3-03.png"],
[UIImage imageNamed:@"backgrounds_app4-04.png"],
nil];
viewer = [[UIImageView alloc] initWithFrame:self.view.frame];
viewer.animationImages = animationImages ;
viewer.animationRepeatCount = 2;
viewer.animationDuration= 4.0;
[viewer startAnimating];
[NSTimer scheduledTimerWithTimeInterval:4.0 target:self
selector:@selector(animationDone:)
userInfo:nil repeats:NO];
}
-(void)animationDone:(NSTimer*)inTimer
{
[inTimer invalidate];
inTimer = nil;
NSLog(@"animationDone ");
}
Upvotes: 0
Views: 847
Reputation: 9387
After initialising the image view, you'll have to add it as a subview:
viewer = [[UIImageView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:viewer];
Upvotes: 2