2

UIRotateGestureRecognizer が既に iOS の一部であることは承知しています。しかし、このジェスチャーには 2 本の指が必要でした。1 本の指だけを必要とする同様のジェスチャ認識機能を実装するにはどうすればよいですか? これをうまく実装した Gyrotate というゲームが AppStore にあります。手がかりをいただければ幸いです。どうも。

4

5 に答える 5

6

Kirby Turner には、完全な 1 本指回転ジェスチャ レコグナイザがあります

于 2011-10-06T16:09:51.900 に答える
5

コードは次のとおりです。これは私のシミュレーターで動作します。マークは、それがあなたが探していたものかどうか答えました。

    // On new touch, start a new array of points
- (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event
{
    self.points = [NSMutableArray array];
    CGPoint pt = [[touches anyObject] locationInView:self];
    [self.points addObject:[NSValue valueWithCGPoint:pt]];
}

// Add each point to the array
- (void) touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event
{
    CGPoint pt = [[touches anyObject] locationInView:self];
    [self.points addObject:[NSValue valueWithCGPoint:pt]];
    [self setNeedsDisplay];
}

// At the end of touches, determine whether a circle was drawn
- (void) touchesEnded:(NSSet *) touches withEvent:(UIEvent *) event
{
    if (!self.points) return;
    if (self.points.count < 3) return;

    // Test 1: The start and end points must be between 60 pixels of each other
    CGRect tcircle;
    if (distance(POINT(0), POINT(self.points.count - 1)) < 60.0f)
        tcircle = [self centeredRectangle];

    // Test 2: Count the distance traveled in degrees. Must fall within 45 degrees of 2 PI
    CGPoint center = CGPointMake(CGRectGetMidX(tcircle), CGRectGetMidY(tcircle));
    float distance = ABS(acos(dotproduct(centerPoint(POINT(0), center), centerPoint(POINT(1), center))));
    for (int i = 1; i < (self.points.count - 1); i++)
        distance += ABS(acos(dotproduct(centerPoint(POINT(i), center), centerPoint(POINT(i+1), center))));
    if ((ABS(distance - 2 * M_PI) < (M_PI / 4.0f))) circle = tcircle;

    [self setNeedsDisplay];
}
于 2010-08-27T03:13:12.317 に答える
3

OneFingerRotationScaleResize、およびClose機能を備えたIQStickerViewを実装しました。

特徴:-

1) ワンフィンガーローテーションスケール。

2) ワンフィンガーリサイズ。

3) プロパティで回転、拡大縮小、サイズ変更を有効/無効にします。

4) 複数の IQStickerView を自動管理します。

5) UIScrollView でも動作します。

6) 速い応答性。

github レポジトリはこちら:- https://github.com/hackiftekhar/IQStickerView

于 2013-08-19T15:49:58.963 に答える
2

UIGestureRecognizerクラスを探索してみてください。を使用してカスタマイズできるはずですUIGestureRecognizerDelegate

于 2010-08-27T02:05:01.457 に答える