【发布时间】:2023-03-19 04:07:01
【问题描述】:
在视图控制器中,我有一个 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
【问题讨论】:
-
这篇文章展示了一个自定义的“圆形滑块”,可能正好包含您需要的信息——特别是在它跟踪将“指示器”保持在圆圈边缘的触摸位置的末尾:raywenderlich.com/…
标签: swift xcode autolayout nslayoutconstraint cmmotionmanager