質問

私は指のアプリで絵を描いています。

起動点とエンドポイントを設定したいです。

私のプロジェクトはこのようなもので、描く方向を伝える背景があります。ユーザーがエンドポイントにヒットすると、背景が変更されます。

私はこれを試しました...タッチで始まりました...

    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
        }

動いていない。

別の方法はありますか?

役に立ちましたか?

解決

Touch MotedまたはEndded MethodでTouch In End RectangleでTouch In End Rectangleを確認する必要があります

- (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
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top