Objectif C: Point de départ et point final
-
27-10-2019 - |
Question
Je fais un dessin avec application doigt.
Je veux définir un point de départ et point final.
Mon projet est comme ça, il a un arrière-plan qui vous dira la direction à dessiner. lorsque l'utilisateur touche le point final l'arrière-plan change.
J'ai essayé ... On touche a commencé ...
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
}
il ne fonctionne pas.
Y at-il une autre façon?
La solution
vous devriez vérifier est tactile dans le rectangle final sur le toucher déplacé ou méthode terminée
- (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
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow