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

时间:2014-04-13 00:47:52

标签: ios button uibutton action

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

代码:

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);

1 个答案:

答案 0 :(得分:1)

这是方法的用途。创建一个采用图像名称的方法:

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

现在让您的按钮处理程序调用两次:

- (IBAction)buttonHandler {
    [self transitionToImage:@"CharacterBackwards.png"];
    [self performSelector:@selector(transitionToImage:) withObject:@"CharacterForwards.png" afterDelay:0.4];
}