0

いくつかの描画に使用されるカスタムdrawRect()メソッドを備えたUIViewがあります。

UIPinchGestureRecognizerを使用してズーム効果を実現しています。

これはアクションメソッドです:

- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
    //NSLog(@"Pinch gesture recognized");

    CGPoint touchOrigin = [recognizer locationInView:self];
    _currentScaleOrigin = touchOrigin;

    if (recognizer.state == UIGestureRecognizerStateEnded)
    {
        NSLog(@"%16@ x = %f, y = %f", @"Pinch end:", touchOrigin.x, touchOrigin.y);
        return;
    }

    if (recognizer.state == UIGestureRecognizerStateChanged)
    {
        //NSLog(@"scale = %f", recognizer.scale);
        NSLog(@"%16@ x = %f, y = %f", @"Pinch origin:", touchOrigin.x, touchOrigin.y);

        // scale has at start a value of 1.0 and increases as fingers moves away from each other
        _currentScaleLevel += recognizer.scale - 1;
        [self setNeedsDisplay]; // call drawRect for redrawing at current scale level
    }

    recognizer.scale = 1;

} 

メッセージを受信UIGestureRecognizerStateEndedすると、座標に奇妙なオフセットが表示されます。

Pinch origin: x = 358.000000, y = 630.000000

Pinch origin: x = 355.000000, y = 627.000000

Pinch origin: x = 353.000000, y = 625.000000

Pinch origin: x = 351.000000, y = 624.000000

Pinch origin: x = 351.000000, y = 623.000000

Pinch origin: x = 350.000000, y = 622.000000

Pinch origin: x = 349.000000, y = 622.000000

Pinch origin: x = 349.000000, y = 622.000000

Pinch end: x = 315.000000, y = 750.000000

...そして無料の翻訳:)私は必要ありません。翻訳がどこから来たのかわかりません。

この翻訳を無効にする方法は?

4

1 に答える 1

0

解決しました。

受け取ったとき、スケーリング変換を行うためUIGestureRecognizerStateEndedの 2 本の指の最後のポイントを my に割り当てていました。_currentScaleOrigin

UIPinchGestureRecognizer が画面上の最後の指の位置の CGPoint を返すことを知りませんでした。

メソッドコード全体は次のとおりです。

- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
#if 1 
    static CGPoint point_0;
    static CGPoint point_1;
    if ([recognizer numberOfTouches] > 1)
    {
        point_0 = [recognizer locationOfTouch:0 inView:self];
        point_1 = [recognizer locationOfTouch:1 inView:self];
        NSLog(@"pinch loc 0: (%f, %f)", point_0.x , point_0.y);
        NSLog(@"pinch loc 1: (%f, %f)", point_1.x , point_1.y);
    } else if ([recognizer numberOfTouches] == 1) {
        point_0 = [recognizer locationOfTouch:0 inView:self];
        NSLog(@"pinch loc 0: (%f, %f)", point_0.x , point_0.y);
    }
#endif

    switch (recognizer.state)
    {
        case UIGestureRecognizerStateBegan:
        {
            CGPoint pointBegin = [recognizer locationInView:self];
            NSLog(@"%16@ x = %f, y = %f", @"Pinch start:", pointBegin.x, pointBegin.y);
        } break;
        case UIGestureRecognizerStateChanged:
        {
            _currentScaleOrigin = [recognizer locationInView:self];

            //NSLog(@"scale = %f", recognizer.scale);
            NSLog(@"%16@ x = %f, y = %f", @"Pinch origin:", _currentScaleOrigin.x, _currentScaleOrigin.y);

            // scale has at start a value of 1.0 and increases as fingers moves away from each other
            _currentScaleLevel += recognizer.scale - 1;
            // call drawRect for redrawing at current scale level
            [self setNeedsDisplay]; 
        } break;
        case UIGestureRecognizerStateEnded:
        {
            CGPoint pointEnded = [recognizer locationInView:self];
            NSLog(@"%16@ x = %f, y = %f", @"Pinch end:", pointEnded.x, pointEnded.y);
            //return;
        } break;
        default : 
        {
            NSLog(@"other state");
        }
    }

    recognizer.scale = 1;
}
于 2012-12-03T11:10:58.987 に答える