2016-11-28 3 views
0

UITouchポイントをオフセットすることはできますか?私は以下のタッチメソッドを使用しています。いくつかの番号でタッチポイントをオフセットして、タッチが開始されて描画される場所をユーザーが確認するようにしたいと思います。私が線の中に描こうとしているなら、ペンや鉛筆のように指先の上を見たい。助けを歓迎します。Objective Cでタッチポイントをオフセットできますか?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 


    // add the first touch 
    UITouch *touch = [touches anyObject]; 

    previousPoint = [touch previousLocationInView:self]; 
    currentPoint = [touch locationInView:self]; 

    // init the bezier path 
    self.currentTool = [self toolWithCurrentSettings]; 
    self.currentTool.lineWidth = self.lineWidth; 
    self.currentTool.lineColor = self.lineColor; 
    self.currentTool.lineAlpha = self.lineAlpha; 

    [self.currentTool setInitialPoint:currentPoint]; 
... 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

    // save all the touches in the path 
    UITouch *touch = [touches anyObject]; 

    previousPoint2 = previousPoint1; 
    previousPoint1 = [touch previousLocationInView:self]; 
    currentPoint = [touch locationInView:self]; 

    //currentPoint.y += 40; 
    CGRect bounds = [(DrawingPenTool*)self.currentTool addPathPreviousPoint:previousPoint2 withPreviousPoint:previousPoint1 withCurrentPoint:currentPoint]; 

     CGRect drawBox = bounds; 
     drawBox.origin.x -= self.lineWidth * 2.0; 
     drawBox.origin.y -= self.lineWidth * 2.0; 
     drawBox.size.width += self.lineWidth * 4.0; 
     drawBox.size.height += self.lineWidth * 4.0; 

     [self setNeedsDisplayInRect:drawBox];  
     [self.currentTool moveFromPoint:previousPoint1 toPoint:currentPoint]; 
     [self setNeedsDisplay]; 
    } 

} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

    [self touchesMoved:touches withEvent:event]; 

     CGPoint point = [[touches anyObject] locationInView:self]; 
     [self.currentTool setInitialPoint:point]; 


     } 

} 

答えて

2

あなたはのタッチは、おそらくされる場所を学ぶためたUIEvent predictedTouchesとUITouch estimatedPropertiesを使用することができます。このようにして、ユーザーの「先を向く」描画を続けることができます。それはまさにこの機能のためのものです。

+2

詳細については、WWDC 2015または2016の「タッチ」ビデオをご覧ください。アプリの描画は、これらの動画のターゲットオーディエンスです。 – matt

+0

ありがとう@matt。 Appleの鉛筆を使用していない場合でも、私はestimatedPropertiesを使用することができますかビデオを見るか2 –

+0

ですか? –

関連する問題