0

長押しで大きな点を描くことはできますか?長押しジェスチャを行うときに線をもっと大きくし、そのポイントを使用してタッチで線を動かしたいからです。これが理にかなっていることを願っています。これが私のコードです。

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

            UITouch *touch = [touches anyObject];
            previousPoint2 = previousPoint1;
            previousPoint1 = currentTouch;
            currentTouch = [touch locationInView:self.view];


            CGPoint mid1 = midPoint(previousPoint2, previousPoint1); 
            CGPoint mid2 = midPoint(currentTouch, previousPoint1);


            UIGraphicsBeginImageContext(CGSizeMake(1024, 768));
            [imgDraw.image drawInRect:CGRectMake(0, 0, 1024, 768)];
            CGContextRef context = UIGraphicsGetCurrentContext();
            CGContextSetLineCap(context,kCGLineCapRound);
            CGContextSetLineWidth(context, slider.value);
            CGContextSetBlendMode(context, blendMode);
            CGContextSetRGBStrokeColor(context,red, green, blue, 1);
            CGContextBeginPath(context);
            CGContextMoveToPoint(context, mid1.x, mid1.y);//Computation
            CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
            CGContextStrokePath(context);

            imgDraw.image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsGetCurrentContext();
}

ここで長押しを挿入するにはどうすればよいですか?

4

2 に答える 2

1

ビューに UILongPressGestureRecognizer を追加する必要があります。次に、このレコグナイザーには、ポイントの半径を増やしてから描画し、ジェスチャが終了したときに半径をデフォルトの開始値にリセットするメソッドが関連付けられている必要があります。

次のようなことを試してください:

-(void)viewDidLoad
{
    [super viewDidLoad];
    UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(drawAndExpandPoint:)];
    [self addGestureRecognizer:recognizer];
}

次に、drawAndExpandPoint メソッドで、次のようなことができます (デフォルト値を持つ radius と呼ばれる ivar を使用):

-(void)drawAndExpandPoint:(UILongPressGestureRecognizer *)recognizer
{ 
    //Reset radius, if gesture ended
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        radius = DEFAULT_RADIUS;
        return;
    }

    else if (radius <= MAX_RADIUS) {
        radius += RADIUS_INCREMENT;
        //You will have to write this method to draw the point
        [self drawAtPoint:[recognizer locationInView:self.view] withRadius:radius];
    }
}

このコードは、あなたが説明した 100% ではないかもしれませんが、ジェスチャ認識エンジンを使用するという一般的な戦略を概説していると思います。これにより、作業がはるかに簡単になります。

于 2012-07-24T17:16:17.317 に答える
0

考えられる解決策の1つ:

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

  • UITouchからをtouchesインスタンス変数に保存します。

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

  • インスタンス変数が設定されているか確認してください。そうである場合は、保存されたタッチと新しいタッチのタイムスタンプの差を計算します。この違いを使用して線幅を決定し、インスタンス変数の設定を解除します。
于 2012-07-24T11:12:36.063 に答える