ios - UIDynamicAnimator/UIAttachmentBehavior 抖动?
<p><p>在使用 Xcode 5.1.1 在 iOS7 中使用新的物理引擎时,我编写了以下代码:</p>
<pre><code>#import "ZViewController.h"
@interface ZViewController ()
@property (nonatomic, strong) UIView *cardView;
@property (nonatomic, strong) UIDynamicAnimator *animator;
@property (nonatomic, strong) UIAttachmentBehavior *attachment;
@end
@implementation ZViewController
- (void)viewDidLoad{
;
self.cardView = [initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
self.cardView.backgroundColor = ;
;
UIPanGestureRecognizer *panGestureRecognizer = [initWithTarget:self action:@selector(panGestureHandler:)];
;
self.animator = [initWithReferenceView:self.view];
}
- (void)viewWillAppear:(BOOL)animated{
;
self.cardView.center = self.view.center;
}
- (void)panGestureHandler:(UIPanGestureRecognizer *)panGesture{
CGPoint touchPoint = ;
switch(panGesture.state){
case UIGestureRecognizerStateBegan:
self.attachment = [initWithItem:self.cardView attachedToAnchor:touchPoint];
;
break;
case UIGestureRecognizerStateChanged:
touchPoint.x = 160.0;
self.attachment.anchorPoint = touchPoint;
break;
case UIGestureRecognizerStateEnded:
;
self.attachment = nil;
break;
default:
break;
}
}
@end
</code></pre>
<p>当我测试这段代码时,我发现了一个非常奇怪的摆动/抖动。在大多数情况下,上下拖动 cardView 可以达到预期的效果,即 cardView 以 x 轴为中心上下滑动,但 cardView 每隔一段时间就会对角线向左移动,然后对角线回到 x 轴中心。这种摆动似乎并非始终如一地发生,但它似乎总是向左摆动。</p>
<p>有人见过这个吗?任何想法是什么原因造成的?如何阻止它?</p>
<p>提前致谢 - AYAL</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我尝试了您的代码并且可以复制该问题。在我设置长度后,它停止了问题。</p>
<p>尝试将附件的长度设置为 1</p>
<pre><code>case UIGestureRecognizerStateBegan:
self.attachment = [initWithItem:self.cardView attachedToAnchor:touchPoint];
self.attachment.length = 1;
;
break;
</code></pre></p>
<p style="font-size: 20px;">关于ios - UIDynamicAnimator/UIAttachmentBehavior 抖动?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23097695/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23097695/
</a>
</p>
页:
[1]