2

所以,这似乎是一个奇怪的现象。我有一个带有自定义背景图像的 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];
}
4

1 回答 1

1

埃斯克拉福德是对的。上面有东西,只是它从不明显在上面。我会添加我的经验,以防其他人遇到同样的问题。

在我的游戏中,有多个具有路径动画的 UIView。它们的初始帧最初设置为 0,0,然后随机调整路径起点。但它们的初始框架覆盖了按钮的顶部。

感谢所有提供反馈的人。

于 2013-06-25T13:57:26.833 回答