I’m trying to do a simple 2 frame animation of a UIButton. I understand that this is possible using the UIButton's imageView.animationImages property – setting it to an array and animating it. But when I do so, nothing appears. FYI, I’ve checked the buttonImages array and it does indeed contain the images I want to show. Any ideas where I’m going wrong?
NSArray *buttonImages = bookDoc.book.buttonImages;
UIImage *bookImage = bookDoc.thumbImage;
UIButton *bookButton = [UIButton buttonWithType:UIButtonTypeCustom];
bookButton.frame = CGRectMake(0, 0, bookImage.size.width, bookImage.size.height);
//[bookButton setBackgroundImage:bookImage forState:UIControlStateNormal];
bookButton.imageView.animationImages = buttonImages;
bookButton.imageView.animationDuration = 0.5;
bookButton.imageView.animationRepeatCount = INFINITY;
[bookButton addTarget:self action:@selector(bookButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[bookButton.imageView startAnimating];
I don’t think I’ve ever tried to save an image to a button’s imageView property. I’ve always used setImage:forState or setBackgroundImage:forState.
My guess is that the button is setting the image property of it’s image view itself, using the (nil) image for the default image state.
Have you tried setting the button.imageView.image property to a static image to see if that works? My guess, as I said, is that the button will overwrite any image you provide with the setting provided in setImage:forState (or nil, if you never provided an image for the current state.)