首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使UIPushBehavior正在操作的视图不旋转那么多?这是一个荒唐的数字

如何使UIPushBehavior正在操作的视图不旋转那么多?这是一个荒唐的数字
EN

Stack Overflow用户
提问于 2014-02-16 13:02:39
回答 1查看 590关注 0票数 3

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

这就是我连接UIPushBehavior的方式

代码语言:javascript
复制
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];
}

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

EN

回答 1

Stack Overflow用户

发布于 2014-04-18 04:46:36

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

代码语言:javascript
复制
UIDynamicItemBehavior* dynamic = [[UIDynamicItemBehavior alloc] initWithItems:@[self.imageView]];
dynamic.allowsRotation = NO;
[self.animator addBehavior:dynamic];

[self.animator addBehavior:self.pushBehavior];

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21807539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档