Reputation: 43
So, this seems like a weird occurrence. I have a UIButton with a custom background image and and animation that is called randomly (it's an image of a buoy rocking back and forth). The strange thing is, only the bottom portion of the button is tappable. I have another button that is identical in the way that is set up, and you can tap anywhere on the image.
The background image is just a png (it has transparency) but the other buttons I've created are work as long as you tap within the bounding box. Any ideas?
-(void)displayPauseButton
{
NSArray *pauseInfo = [self.sharedGameModel.theAssets objectForKey:@"buoy-ani"];
//
// add mascot button
// aButtonArray has the info for a individual button in an array
// the buttons are read from the array in this order
// 0 array of images for the button animation triggered when clicked
// 1 x position
// 2 y position
// this array only has the names of the image animation
// so we init
NSArray *pauseImages = [pauseInfo objectAtIndex:0];
UIImage *pauseImage = [UIImage imageNamed:[pauseImages objectAtIndex:0]];
CGFloat theX=[[pauseInfo objectAtIndex:1] floatValue];
CGFloat theY=[[pauseInfo objectAtIndex:2] floatValue];
// create a new mutable array to fill with the actual object
// in the following loop
NSMutableArray *buttonAniImages = [[NSMutableArray alloc] init];
for (id object in pauseImages)
{
[buttonAniImages addObject:[UIImage imageNamed:object]];
}
// sets the custom image for the button
[self.pauseButton setImage:pauseImage forState:UIControlStateNormal];
self.pauseButton.frame = CGRectMake(theX, theY, pauseImage.size.width, pauseImage.size.height);
self.pauseButton.imageView.animationImages = buttonAniImages;
self.pauseButton.imageView.animationDuration=3.0;
self.pauseButton.imageView.animationRepeatCount=1;
[self.gameScreen addSubview:self.pauseButton];
// add the action associated with the button
[self.pauseButton addTarget:self action:@selector(someoneHitThePauseButton:) forControlEvents:UIControlEventTouchUpInside];
}
Upvotes: 2
Views: 820
Reputation: 43
Escrafford is right. There was something on top, only it was never visibly on top. I'll add my experience just in case anyone else runs into the same issue.
In my game, there are multiple UIViews that have path animations. Their initial frames were initially set to 0,0 and then the path starting points were adjusted randomly. But their initial frames were covering the top portion of the buttons.
Thanks to everyone who provided feedback.
Upvotes: 1