How to Make A button do more than one action xcode

前端 未结 1 1232
别跟我提以往
别跟我提以往 2021-01-29 14:32

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          


        
相关标签:
1条回答
  • 2021-01-29 14:59

    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];
    }
    
    0 讨论(0)
提交回复
热议问题