如何使一个按钮执行多个操作 xcode

How to Make A button do more than one action xcode(如何使一个按钮执行多个操作 xcode)

本文介绍了如何使一个按钮执行多个操作 xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以在我的 Xcode 项目中,我有一个按钮,我需要两次执行相同的方法,但使用不同的图像请帮助

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

代码:

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];
}

这篇关于如何使一个按钮执行多个操作 xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何使一个按钮执行多个操作 xcode

基础教程推荐