3

現在、UIPushBehaviorユーザーがUIPanGestureRecognizer. それは機能しますが、私の問題は、ビューが途方もなく回転することです...まるでスポーツカーのタイヤに取り付けられているようです.

これは私が添付する方法ですUIPushBehavior

else if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
    [self.animator removeBehavior:self.panAttachmentBehavior];

    self.pushBehavior = [[UIPushBehavior alloc] initWithItems:@[self.imageView] mode:UIPushBehaviorModeInstantaneous];
    [self.pushBehavior setTargetOffsetFromCenter:centerOffset forItem:self.imageView];
    self.pushBehavior.active = YES;

    CGPoint velocity = [panGestureRecognizer velocityInView:self.view];
    CGFloat area = CGRectGetWidth(self.imageView.bounds) * CGRectGetHeight(self.imageView.bounds);
    CGFloat UIKitNewtonScaling = 1000000.0;
    CGFloat scaling = area / UIKitNewtonScaling;
    CGVector pushDirection = CGVectorMake(velocity.x * scaling, velocity.y * scaling);

    self.pushBehavior.pushDirection = pushDirection;

    [self.animator addBehavior:self.pushBehavior];
}

それをさらに操作するために何を変更する必要があるのか​​ 正確にはわかりません。速度とすべてが完璧です。私はそれがばかげて回転することを望んでいません.

4

1 に答える 1

2

手遅れかもしれませんが、回転を完全に排除したい場合は、次のようにします。

UIDynamicItemBehavior* dynamic = [[UIDynamicItemBehavior alloc] initWithItems:@[self.imageView]];
dynamic.allowsRotation = NO;
[self.animator addBehavior:dynamic];

そしてその[self.animator addBehavior:self.pushBehavior];

于 2014-04-17T20:46:36.213 に答える