Pregunta

Estoy haciendo un dibujo con la aplicación Finger.

Quiero establecer un punto de inicio y un punto final.

Mi proyecto es así, tiene un fondo que le dirá la dirección para dibujar. Cuando el usuario llega al punto final, el fondo cambiará.

Intenté esto ... en los toques comenzó ...

    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
        }

no funciona.

¿Hay otra manera?

¿Fue útil?

Solución

Debe verificar el rectángulo del extremo en el método conmovido o finalizado

- (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
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top