所以,这似乎是一个奇怪的现象。我有一个带有自定义背景图像的 UIButton 和随机调用的动画(它是一个来回摇摆的浮标图像)。奇怪的是,只有按钮的底部是可点击的。我有另一个按钮,其设置方式相同,您可以点击图像上的任意位置。
背景图像只是一个 png(它具有透明度),但只要您在边界框中点击,我创建的其他按钮就可以使用。有任何想法吗?
-(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];
}