Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIButton赢得';不要以编程方式更改边界_Objective C_Xcode_Uibutton_Bounds - Fatal编程技术网

Objective c UIButton赢得';不要以编程方式更改边界

Objective c UIButton赢得';不要以编程方式更改边界,objective-c,xcode,uibutton,bounds,Objective C,Xcode,Uibutton,Bounds,我正在制作一个iPhone游戏,让用户在游戏中选择他们想要的汽车颜色。为了显示哪些车可以被选择,我有一些带有背景图像的按钮,这些背景图像是各种各样的车。为了显示当前选择的汽车,我在当前汽车颜色后面有一个按钮,背景颜色为黄色。我想发生的是,当你点击一个汽车按钮时,黄色按钮会在被点击的按钮后面移动。我的代码如下所示: -(void)setPlayerCar:(UIButton *)newCar{ //this code is being called when any of the

我正在制作一个iPhone游戏,让用户在游戏中选择他们想要的汽车颜色。为了显示哪些车可以被选择,我有一些带有背景图像的按钮,这些背景图像是各种各样的车。为了显示当前选择的汽车,我在当前汽车颜色后面有一个按钮,背景颜色为黄色。我想发生的是,当你点击一个汽车按钮时,黄色按钮会在被点击的按钮后面移动。我的代码如下所示:

    -(void)setPlayerCar:(UIButton *)newCar{
    //this code is being called when any of the buttons is clicked
    NSArray *carFiles = [NSArray arrayWithObjects:@"redCar.png",@"blueCar.png",@"greenCar.png",@"purpleCar.png",@"turquioseCar.png",@"yellowCar.png", nil];
    NSString *file = [carFiles objectAtIndex:newCar.tag];
    currentCarImage = file;
    CGRect frame;
    if(currentCarImage == @"redCar.png"){
        frame = CGRectMake(48, 78, 30, 30);
    }
    if(currentCarImage == @"blueCar.png"){
        frame = CGRectMake(83, 78, 30, 30);
    }
    if(currentCarImage == @"greenCar.png"){
        frame = CGRectMake(118, 78, 30, 30);
    }
    if(currentCarImage == @"purpleCar.png"){
        frame = CGRectMake(153, 78, 30, 30);
    }
    if(currentCarImage == @"turquioseCar.png"){
        frame = CGRectMake(188, 78, 30, 30);
    }
    if(currentCarImage == @"yellowCar.png"){
        frame = CGRectMake(223, 78, 30, 30);
    }
    for(UIButton *button in self.pauseScroll.subviews){
        if(button.backgroundColor == [UIColor yellowColor]){
           button.bounds = frame;
        }
        if(button.tag == newCar.tag){
           [self.pauseScroll bringSubviewToFront:button];
        }
    }
}

据我所知,这应该将黄色按钮移到选中的按钮上。问题是这不会发生,当我调试时,我发现正确的按钮被识别,帧被赋予了正确的值,并且行:button.bounds=frame;正在执行,但当我查看正在显示的内容时,没有任何更改

您应该更改按钮的
,而不是
边界
。视图的
边界
描述了视图在其自身坐标空间中的位置和大小。
帧是superview坐标空间中的大小和位置

if (button.backgroundColor == [UIColor yellowColor]) {
    button.frame = frame;
}

<代码> CurrnCalMaseI= @“ReCal.PNG”< /Cord>这不是你需要比较的字符串>代码> [CurrnCalIsIsAutotoStult:@“ReCal.PNG”] /代码>我也会考虑更改<代码>如果语句到<代码>,如果是< /Cord>语句,这样你就不会每次都执行每个测试。另外,
carFiles
数组最好放在ivar中最有可能的其他位置