Second touch animation(第二次触摸动画)
问题描述
尝试掌握 Xcode 并在过去几周似乎取得了一些进展.
Trying to get to grips with Xcode and seem to be making some progress over the last few weeks.
有谁知道自定义按钮可以在第二次点击时执行一组不同的动画.
Does anyone know a way that a custom button can do a different set of animations on a second click.
假设我有一个自定义按钮及其马里奥,当我点击它时,他从屏幕中间跑出屏幕右侧,然后从左侧跑回中间屏幕上,他也会发出声音.
So let say I have a custom button and its of Mario, when i click it he runs from the middle of the screen and out of the right hand side of the screen and then runs back in to the middle from the left of the screen, he also makes noise.
我使用以下代码实现了这一点:
I have achieved this using this code:
- (IBAction)marioRunning_clicked:(id)sender
{
[UIView animateWithDuration:1.50 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
marioRunning.center = CGPointMake(350.5, 456.0);
} completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:0.00 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
marioRunning.center = CGPointMake(-30.5, 456.0);
} completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:1.50 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
marioRunning.center = CGPointMake(160.0, 456.0);
} completion:^(BOOL finished) {
if(finished) // NSLog ( @"Finished !!!!!" );
marioRunning.center = CGPointMake(160.0, 456.0);
}];
}
}];
}
}];
marioRunning.imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"mario-running2"],[UIImage imageNamed:@"mario-running3"],nil];
marioRunning.imageView.animationDuration = 0.15;
marioRunning.imageView.animationRepeatCount = 19;
[marioRunning.imageView startAnimating];
}
我怎样才能让他在下次点击时制作第二组动画?例如,如果我第二次点击他,而不是从左到右运行,他会上下跳跃?
How could I make him do a second set of animations on the next click? For example instead of running from left to right, if i tap him the second time he will Jump up and down?
推荐答案
使用按钮的选中状态来决定做哪个动画
Use the selected state of the button to decide which animation to do
-(void)buttonClicked:(UIButton*)button
{
if(button.selected)
{
[self doAnimation1];
}
else
{
[self doAnimation2];
}
button.selected = !button.selected;
}
这篇关于第二次触摸动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:第二次触摸动画


基础教程推荐
- :hover 状态不会在 iOS 上结束 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01