Swift:将对象约束并指向圆形NSLayoutConstraint吗?圆锚?

问题描述 投票:0回答:1

[在视图控制器中,我有一个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
swift xcode autolayout nslayoutconstraint cmmotionmanager
1个回答
0
投票

我会尝试使用UIKit Dynamics,尤其是UICollisionBehavior,它允许使用贝塞尔曲线定义碰撞边界。

© www.soinside.com 2019 - 2024. All rights reserved.