[在视图控制器中,我有一个UIView(backgroundCircle)和一个UILabel。 UILabel基于motionManager.startAccelerometerUpdates数据移动。使用此数据,我使label.center点动画化。但是,我想对运动进行限制,以使其仅在围绕其起点的圆形区域内运动(就像它在从起点起的皮带上)。这可能吗?如果有帮助,请参见下面的示例代码。
//objects called during set up
let backgroundCircle = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
backgroundCircle.layer.cornerRadius = circle.frame.width / 2
backgroundCircle.backgroundColor = .clear
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
label.text = "Hello"
//this is called in a separate function, continuously
label.center = newCenter
我会尝试使用UIKit Dynamics,尤其是UICollisionBehavior
,它允许使用贝塞尔曲线定义碰撞边界。