Frage

Ich mache eine Zeichnung mit der Finger -App.

Ich möchte einen Startpunkt und einen Endpunkt festlegen.

Mein Projekt ist so, es hat einen Hintergrund, der Ihnen die Richtung zum Zeichnen zeigt. Wenn der Benutzer den Endpunkt trifft, ändert sich der Hintergrund.

Ich habe es ausprobiert ... bei Berührungen begann ...

    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
        }

es funktioniert nicht.

Gibt es eine andere Art und Weise?

War es hilfreich?

Lösung

Sie sollten überprüfen, ob Sie das Rechteck auf der Berührung von Touch bewegt sind oder beendet sind. Methode

- (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
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top