gpt4 book ai didi

ios - 如何使由 UIPushBehavior 操纵的 View 不旋转太多?这是一个荒谬的数量

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:07 25 4
gpt4 key购买 nike

现在,我有一个 UIPushBehavior,我在 View 上使用它根据用户使用 UIPanGestureRecognizer 触摸的位置将其推离屏幕。它有效,但我的问题是 View 旋转了一个荒谬的量......就像它附在跑车的轮胎上一样。

这就是我附加 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];
}

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

最佳答案

也许为时已晚,但如果您想完全消除旋转,请执行以下操作:

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

[self.animator addBehavior:self.pushBehavior];

关于ios - 如何使由 UIPushBehavior 操纵的 View 不旋转太多?这是一个荒谬的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21807539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com