主要用到方法:
1.定义一个数组存储图片,并实现动画:
NSArray *hopAnimation;
hopAnimation=@[
0 [UIImage imageNamed:@"frame-1.png"],
[UIImage imageNamed:@"frame-2.png"],
[UIImage imageNamed:@"frame-3.png"],
......];
self.bunnyView2.animationImages=hopAnimation;
self.bunnyView1.animationImages=hopAnimation;
self.bunnyView3.animationImages=hopAnimation;
.......
self.bunnyView1.animationDuration=1;
self.bunnyView2.animationDuration=1;
self.bunnyView3.animationDuration=1;
......
2.设置 滑块,并将速度值显示在标签,设置时,若动画未开始,将启动动画:
其中value最大时,速度反而小。此处定义一个常量2,将2-value 值显示
- (IBAction)setSpeed:(id)sender {
NSString *hopRatString;
self.bunnyView1.animationDuration=2-self.speedStepper.value;
self.bunnyView2.animationDuration=self.bunnyView1.animationDuration+((float)rand()%11+1)/10);
[self.bunnyView1 startAnimating];
[self.toggleButton setTitle:@"Sit Still" forState:UIControlStateNormal];
hopRatString=[NSStringstringWithFormat:@"%1.2f hpa",1/(2-self.speedStepper.value)];
self.hopARateString.text=hopRatString;
}
3:设置开始,关闭按钮:
- (IBAction)toggleAnimation:(id)sender {
if (self.bunnyView1.isAnimating) {
[self.bunnyView1 stopAnimating];
......
[self.toggleButton setTitle:@"Hop!" forState:UIControlStateNormal];
}else{
[self.bunnyView3 startAnimating];
.......
[self.toggleButton setTitle:@"Sit Still!" forState:UIControlStateNormal];
}
4.设置 步进按钮,由于之前写好滑块方法,直接利用- (IBAction)setIncrement:(id)sender {
self.speedSlider.value=self.speedStepper.value;
[self setSpeed:nil];
}
5修复状态栏看不清问题:-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent; //浅色 UIStatusBarStyleLightContent // 深色状态栏
}