我正试着用“blockView”来形容UIPanGestureRecognizer。当“结束”时,希望“blockView”以惯性减速,就像UIScrollView以惯性结束滚动一样。

override func viewDidLoad() {
super.viewDidLoad()
self.dynamicAnimator = UIDynamicAnimator(referenceView: self.view)
let collider = UICollisionBehavior(items: [self.magnifiedView!])
collider.collisionDelegate = self
collider.collisionMode = .Boundaries
collider.translatesReferenceBoundsIntoBoundary = true
self.dynamicAnimator.addBehavior(collider)
self.dynamicProperties = UIDynamicItemBehavior(items: [self.magnifiedView!])
//self.dynamicProperties.elasticity = 1.0
//self.dynamicProperties.friction = 0.0
self.dynamicProperties.allowsRotation = false
//self.dynamicProperties.resistance = 10.0
self.dynamicAnimator.addBehavior(self.dynamicProperties)
}
func panBlockView (panGesture: UIPanGestureRecognizer) {
switch panGesture {
case .Began:
self.blockViewLocation = (self.blockView.center)!
case .Changed:
let translation = panGesture.translationInView(self.view)
self.blockView.center = CGPointMake(self.blockViewLocation.x + translation.x, self.self.blockViewLocation.y + translation.y)
case .Ended, .Cancelled:
self.dynamicAnimator.addLinearVelocity(panGesture.velocityInView(self.view), forItem: self.blockView)
}
}问题:当我浏览视图时,“blockView”试图找到pan的起源。当平底锅“结束”时,它会产生惯性,但它从平底锅的起源开始(在拍到锅原点之后)。
注意:上面的代码只为浏览视图而工作,不存在任何问题。
发布于 2016-08-16 15:45:45
添加一个快照行为并让它修复这个问题。
https://stackoverflow.com/questions/38707429
复制相似问题