“CGRectContainsPoint”参数2的不兼容类型

时间:2011-05-23 04:55:13

标签: iphone cocoa-touch xcode

长话短说....

我在所有3个if语句([rubin1 frame],grid [x] [y]的网格[x] [y] .frame部分的'CGRectContainsPoint'的参数2上得到不兼容的类型] .frame),([rubin2 frame],grid [x] [y] .frame)和([rubin3 frame],grid [x] [y] .frame)。我尝试使用[grid [x] [y] frame]但是也遇到了同样的错误。

我想能够在网格上移动rubin 1,rubin2和rubin3,直到我在砖上释放它们。当我在砖上释放它们时,我希望这块砖和其他任何类型的砖一样消失,就像rubin留在哪里的砖(无论它们在网格上的哪个位置)

for (int y = 0; y < BRICKHEIGHT; y++)
{
    for (int x = 0; x < BRICKWIDTH; x++) 
    {


        if (CGRectContainsPoint([rubin1 frame], grid[x][y].frame)) {

            if(grid[x][y].tag == 1){

                ruby--;
                rubin1.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 2){

                ruby--;
                rubin1.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 3){

                ruby--;
                rubin1.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 4){

                ruby--;
                rubin1.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 5){

                ruby--;
                rubin1.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 6){

                ruby--;
                rubin1.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }


        } 
        if (CGRectContainsPoint([rubin2 frame], grid[x][y].frame)) {

            if(grid[x][y].tag == 1){

                ruby--;
                rubin2.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 2){

                ruby--;
                rubin2.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 3){

                ruby--;
                rubin2.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 4){

                ruby--;
                rubin2.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 5){

                ruby--;
                rubin2.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 6){

                ruby--;
                rubin2.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }

        } 
        if (CGRectContainsPoint([rubin3 frame], grid[x][y].frame)) {

            if(grid[x][y].tag == 1){

                ruby--;
                rubin3.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 2){

                ruby--;
                rubin3.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 3){

                ruby--;
                rubin3.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 4){

                ruby--;
                rubin3.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 5){

                ruby--;
                rubin3.alpha = 0;
                grid[x][y].alpha = 0;
                [self PlayerScore: x y: y];

            }
            else if(grid[x][y].tag == 6){

                ruby--;
                rubin3.alpha = 0;
                grid[x][y].alpha = 0;





            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

它期望一个点作为第二个参数而不是帧CGRect。尝试grid [x] [y] .frame.origin。原点为您提供框架CGRect的右上角,.size为CGRect的宽度/高度。

答案 1 :(得分:0)

你必须这样使用。例如:

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:touch.view];

if(CGRectContainsPoint(myimage.frame, location) == 0){
//always end up here
}