Jelter
Jelter

Reputation: 7

Disabling Animation After The Button Is Pressed

This button is a series of images that animate a glowing effect, when the button is pressed I'd like the animation to stop:

[self.buttonHintdisabled setBackgroundImage: [UIImage animatedImageNamed:@"c" duration:3.0] forState: UIControlStateNormal];

How is this done?

If there is another way to do this in code that could disable it when the button is pressed, please let me know?

Upvotes: 0

Views: 893

Answers (2)

Unheilig
Unheilig

Reputation: 16292

I haven't tried this on a UIButton, but I will give you an idea how I would do it:

Often times we set a target with our UIButton:

[self.buttonHintdisabled addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

Within buttonPressed:, we would carry out what we would like to do when the button is pressed.

So, with that in mind, in addition to what you would like to do within buttonPressed, you could try:

[self.buttonHintdisabled setBackgroundImage:[UIImage imageNamed:@"c0.png"]  forState:UIControlStateSelected];

Once the action within that method is done, set it back using what you have above:

[self.buttonHintdisabled setBackgroundImage:[UIImage animatedImageNamed:@"c" duration:3.0] forState: UIControlStateNormal];    

Upvotes: 1

HMHero
HMHero

Reputation: 2343

if you want to use selected button state (UIControlStateSelected)

add this line

[self.buttonHintdisabled setBackgroundImage: [UIImage imageNamed:@"selectedImage"] forState: UIControlStateSelected];

and then in its action

- (void)buttonClicked:(id)sender 
{
     [self.buttonHintdisabled setSelected:YES];
}

or if you can just replace background image in - (void)buttonClicked:(id)sender

Upvotes: 0

Related Questions