gpt4 book ai didi

ios - View 在移动时不会发生碰撞(Swift iOS)

转载 作者:行者123 更新时间:2023-11-28 13:14:51 24 4
gpt4 key购买 nike

我正在尝试在我的应用程序中使用一些 View ,并且我正在尝试通过相互碰撞来动画和碰撞这些 View ,但问题是当我使用重力时,这些 View 会发生碰撞 但是当我拖动/移动任何 View 碰撞时都不起作用。我的代码出了什么问题这里是我的代码

移动 View

  func tappedMe(gr: UIPanGestureRecognizer)
{
if gr.view?.tag == 1{
let point = gr.locationInView(self.view);
square.center.x=point.x
square.center.y=point.y
}else if gr.view?.tag == 2{
let point = gr.locationInView(self.view);
square2.center.x=point.x
square2.center.y=point.y
}
}

重力

animator = UIDynamicAnimator(referenceView: view)
gravity = UIGravityBehavior(items: [square, square2])
let direction = CGVectorMake(0, -1)
gravity!.gravityDirection = direction
animator.addBehavior(gravity)

对于碰撞

collision = UICollisionBehavior(items: [ square, square2])
collision.translatesReferenceBoundsIntoBoundary = true
animator.addBehavior(collision)

提前致谢

最佳答案

我认为您不应该在 View 附加到 UIDynamicAnimator 时直接操作 View 。我认为您要么需要删除所有行为,要么在触摸点添加附着行为并在平移手势期间移动附着点。

(凭内存,最近没用过UIDynamics)

关于ios - View 在移动时不会发生碰撞(Swift iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29411361/

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