您应该检查触摸移动或结束方法时是否触摸结束矩形
- (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
}