如何使一个按钮做多个动作X code [英] How to Make A button do more than one action xcode
本文介绍了如何使一个按钮做多个动作X code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
确定,所以在我的X code项目,我有一个按钮,我需要做同样的方法两次,但不同的图像plz帮助
code:
的UIImage * toImage = [UIImage的imageNamed:@CharacterBackwards.png];
[UIView的transitionWithView:self.view
持续时间:0.01F
选项:UIViewAnimationOptionTransitionNone
动画:^ {
自> Guy.image = toImage;
}完成:NULL];睡眠(0.4);
解决方案
这是什么方法都是。创建需要的图像名称的方法:
- (无效)transitionToImage:(* NSString的)imageName {
*的UIImage = toImage [UIImage的imageNamed:@CharacterBackwards.png];
[UIView的transitionWithView:self.view
持续时间:0.01F
选项:UIViewAnimationOptionTransitionNone
动画:^ {
自> Guy.image = toImage;
}完成:NULL];
}
现在有你的按钮处理程序调用此两次:
- (IBAction为)buttonHandler {
[个体经营transitionToImage:@CharacterBackwards.png];
[自performSelector:@选择(transitionToImage :) withObject:@CharacterForwards.pngafterDelay:0.4];
}
Ok So In My Xcode project I Have A button That I need to do the same method twice but with A Different Image Plz Help
Code:
UIImage * toImage = [UIImage imageNamed:@"CharacterBackwards.png"];
[UIView transitionWithView:self.view
duration:0.01f
options:UIViewAnimationOptionTransitionNone
animations:^{
self->Guy.image = toImage;
} completion:NULL];
sleep(0.4);
解决方案
This is what methods are for. Create a method that takes an image name:
- (void)transitionToImage:(NSString *)imageName {
UIImage * toImage = [UIImage imageNamed:@"CharacterBackwards.png"];
[UIView transitionWithView:self.view
duration:0.01f
options:UIViewAnimationOptionTransitionNone
animations:^{
self->Guy.image = toImage;
} completion:NULL];
}
Now have your button handler call this twice:
- (IBAction)buttonHandler {
[self transitionToImage:@"CharacterBackwards.png"];
[self performSelector:@selector(transitionToImage:) withObject:@"CharacterForwards.png" afterDelay:0.4];
}
这篇关于如何使一个按钮做多个动作X code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文