下面的范例App演示了如下控件的使用,通过滑块、步进控件和按钮来控制在图像视图中播放动画。
图像视图(UIImageView)
滑块(UISlider)
步进控件(UIStpper)
范例App的运行效果,如下图所示:
在图像视图中实现动画效果的部分代码:
- (IBAction)toggleAnimation:(id)sender { if(bunnyView1.isAnimating){ [self.bunnyView1 stopAnimating];[self.bunnyView2 stopAnimating];[self.bunnyView3 stopAnimating];[self.bunnyView4 stopAnimating];[self.bunnyView5 stopAnimating];[self.toggleButton setTitle:@"跳跃吧!" forState:UIControlStateNormal];}else{ [self.bunnyView1 startAnimating];[self.bunnyView2 startAnimating];[self.bunnyView3 startAnimating];[self.bunnyView4 startAnimating];[self.bunnyView5 startAnimating];[self.toggleButton setTitle:@"停 止" forState:UIControlStateNormal];}}
。