OGeek|极客世界-中国程序员成长平台

标题: ios - UIButton 只能部分点击 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:56
标题: ios - UIButton 只能部分点击

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

    // 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 actionselector(someoneHitThePauseButton forControlEvents:UIControlEventTouchUpInside];
}



Best Answer-推荐答案


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

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

感谢所有提供反馈的人。

关于ios - UIButton 只能部分点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17221268/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4