现在,我在视图上使用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];
}
我不知道我应该改变什么来更多地操纵它。速度和一切都很完美,我只是不希望它旋转得那么荒谬。
答案 0 :(得分:2)
也许为时已晚,但如果你想彻底消除轮换,请执行以下操作:
UIDynamicItemBehavior* dynamic = [[UIDynamicItemBehavior alloc] initWithItems:@[self.imageView]];
dynamic.allowsRotation = NO;
[self.animator addBehavior:dynamic];
和[self.animator addBehavior:self.pushBehavior];