繁体   English   中英

UIButton只能部分轻按

[英]UIButton only partially tappable

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

Escrafford是正确的。 有东西在上面,只有它从来没有明显地在上面。 我将补充我的经验,以防其他人遇到相同的问题。

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

感谢所有提供反馈的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM