Animation is Easy, today We learning basic Animation use UIImageView(just like play film).
First need prepare a set of image frames, you can use PhotoShop or any other image edit tool do this.
Second Open Xcode , setup a project from "Single view Application" template.
Three some type
@interface KKViewController ()
@property (strong, nonatomic) IBOutlet UIImageView *gear;
@property (strong, nonatomic) IBOutlet UIButton *actionBtn;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *images=[NSMutableArray arrayWithCapacity:36];
for (int i=0; i< 36; i++) {
[images addObject:[UIImage imageNamed:[NSString stringWithFormat: @"GearAnimation%d",i]]];
}
_gear.animationImages = images;
_gear.animationDuration = [_gear.animationImages count] / 30;
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)startStopAction:(id)sender {
if ([_gear isAnimating]) {
[_gear stopAnimating];
[_actionBtn setTitle:@"Stop" forState:UIControlStateNormal];
}else{
[_gear startAnimating];
[_actionBtn setTitle:@"Start" forState:UIControlStateNormal];
}
}
don't forget to make connect in nib file or storyboard.
Let's go , woo!
It's too simple ?
I upload project code to github, you can download from here

没有评论:
发表评论