2012-02-17 115 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

相關問題