steven
steven

Reputation: 698

Animating a button to look like a spinner on click

So basically I have a button. When it is clicked the first time I want it to display a spinner animation (kind of like the game twister, the spinner thing). I want this animation on the button itself. Preferably as the background. I have the other part of the button working correctly where when it is pressed again it stops pointing in a direction at random. Any ideas on how to get this working?

-(IBAction)spinnerButton:(id)sender{
NSString *display;
if (pressCount%2 == 0) {
    NSString *spinning;
    spinning = @"Press again to stop spinner.";
    display = [[NSString alloc] initWithFormat:@"%@",spinning];

    sender.animationImages = [NSArray arrayWithArray: imageArray];
    sender.animationDuration = 1.0;
    sender.animationRepeatCount = 0;
    sender.startAnimating;
}

The imageArray is put together here.

- (void)viewDidLoad
{
    [super viewDidLoad];


imageArray = [[NSMutableArray alloc] initWithCapacity:8];

for (int i = 0; i < 8; i++) {
    [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"piece%d.png", i]]];
}
}

My thought is that it needs to look something like this

[sender setBackgroundImage:[UIImage imageNamed:@"piece1.png"] forState:UIControlStateNormal];

but I'm not exactly sure how to place the array in it and make set the duration and all that stuffs. Thanks any help is welcomed and appreciated.

Upvotes: 0

Views: 178

Answers (1)

steven
steven

Reputation: 698

I got it to work fine. I placed an Image View over the top of the button. It still allowed me to click the button and it allowed me to tie the images and animation in correctly.

Upvotes: 1

Related Questions