如何使我的UIPushBehavior操纵的视图旋转不那么多?这是一个荒谬的数额

时间:2014-02-16 05:02:39

标签: ios objective-c uiview ios7 uikit-dynamics

现在,我在视图上使用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];
}

我不知道我应该改变什么来更多地操纵它。速度和一切都很完美,我只是不希望它旋转得那么荒谬。

1 个答案:

答案 0 :(得分:2)

也许为时已晚,但如果你想彻底消除轮换,请执行以下操作:

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

[self.animator addBehavior:self.pushBehavior];