0

我想确定点击的位置是否在区域内。我有 4 个 CGPoints,我知道这可以通过使用 UITouch 来完成。另外,我使用该功能在屏幕上点击了位置

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *myTouch = [[touches allObjects] objectAtIndex: 0];
    CGPoint currentPos = [myTouch locationInView:self.view];
}

例如我的 4 个 CGPoints 是

self.firstPoint = CGPointMake(50.0f, 50.0f);
self.secondPoint = CGPointMake(200.0, 50.0);
self.thirdPoint = CGPointMake(200.0, 200.0);
self.fourthPoint = CGPointMake(50.0, 120.0);

提前致谢

4

2 回答 2

2

您应该使用 aCGRect来表示 rect 而不是四个CGPoints,然后使用CGRectContainsPoint()来检查 rect 是否包含该点。

于 2013-06-27T12:45:39.013 回答
1
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {


  UITouch *touch = [[event allTouches] anyObject];
     CGPoint location = [touch locationInView:touch.view];
    image=[UIImage imageNamed:@"anyImage.gif"];
    newView = [[UIImageView alloc]initWithImage:image];
    if (location.y<480|| location.y>50)
    {
        //write your code

    }


}
于 2013-06-27T12:59:10.697 回答