2012-02-17 94 views
0

我正在用手指应用绘制图形。目标C:开始点和结束点

我想设置一个起点和终点。

我的项目是这样的,它有一个背景可以告诉你画的方向。当用户点击终点时,背景将会改变。

我想这... 上的触摸开始......

drawPoint = [touch locationInView:self.view]; 
    CGRect writingStartPoint = CGRectMake(90, 800, 30, 30); 
    CGRect writingEndPoint = CGRectMake(390, 800, 30, 30); 

    if (CGRectContainsPoint(writingStartPoint, drawPoint)) 
    { 
     //something 
    } 

    if (CGRectContainsPoint(writingEndPoint, drawPoint)) 
     { 
      //change background 
     } 

它不工作。

还有别的办法吗?

+0

首先90 800听起来像它的关闭您的看法?如果你的肖像,我可能是错的。其次,记录您的绘图点并确保它与您的绘图处于相同的坐标系中。 – 2012-02-17 04:16:08

回答

1

你应该检查是在触摸结束矩形触摸移动或结束方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    CGPoint drawPoint = [touch locationInView:self.view]; 
    CGRect writingStartPoint = CGRectMake(90, 800, 30, 30); 
    if (CGRectContainsPoint(writingStartPoint, drawPoint)) 
    { 
     //something 
    } 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    CGPoint drawPoint = [touch locationInView:self.view]; 
    CGRect writingEndPoint = CGRectMake(390, 800, 30, 30); 
    if (CGRectContainsPoint(writingEndPoint, drawPoint)) 
    { 
     //change background if you want user see change without lift finger up 
    } 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    CGPoint drawPoint = [touch locationInView:self.view]; 
    CGRect writingEndPoint = CGRectMake(390, 800, 30, 30); 
    if (CGRectContainsPoint(writingEndPoint, drawPoint)) 
    { 
     //change background when user lift finger up 
    } 
} 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { 
    // handle cancel event 
} 
+0

非常感谢你! – SeongHo 2012-02-17 04:48:01

相关问题