我做了一个圆圈路径,圆圈路径的中心位于视图的中间.然后,我做了一个只能在圆圈路径上移动的球(至少这是我想要的):

我做了一个函数,无论我在哪里拖动它都会移动球(仅限于圆形路径),但出于某种原因,每当我拖动它时,它就会变得疯狂并且不会移动,因为我希望它移动.
到目前为止这是我的代码:
class ViewController: UIViewController {
var midViewX = CGFloat()
var midViewY = CGFloat()
var circlePath2 = UIBezierPath()
var shapeLayer2 = CAShapeLayer()
override func viewDidLoad() {
super.viewDidLoad()
midViewX = view.frame.midX
midViewY = view.frame.midY
// Do any additional setup after loading the view, typically from a nib.
let circlePath = UIBezierPath(arcCenter: CGPoint(x: midViewX,y: midViewY), radius: CGFloat(100), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.CGPath
shapeLayer.fillColor = UIColor.clearColor().CGColor
shapeLayer.strokeColor = UIColor.redColor().CGColor
shapeLayer.lineWidth = 3.0
view.layer.addSublayer(shapeLayer) …Run Code Online (Sandbox Code Playgroud) 我试图找到为什么自定义UIButton集合不起作用.在我之前的文章中描述的版本中,我在Swift 3中以编程方式创建了一个UIButton圆圈,并将圆圈固定在屏幕的中心.该版本使用了UIView的子类 - 基于Apple Swift教程(实现Button Action) - 以及利用Imanou Petit优秀代码示例(No.6 Anchor)的autolayout实现.在那个版本中,我设法让我的按钮在iPhone旋转时成功旋转,但按钮动作目标无法工作.
所以我现在尝试使用viewcontroller而不是UIView的子类的替代版本.这次相同的按钮动作目标有效,但旋转手机会使图像偏离中心,如下所示.
每次旋转时,以下消息也会在Xcode的调试区域中出现两次.
***[App] if we're in the real pre-commit handler we can't
actually add any new fences due to CA restriction***
Run Code Online (Sandbox Code Playgroud)
该消息在四个中发生三次,即当手机上下颠倒时没有消息.当我运行上一篇文章中的代码或下面显示的代码时,会发生这种情况.并且在每种情况下,"倒置"框是否已选中或未选中都没有区别.
我也试过禁用OS_ACTIVITY MODE但除了隐藏可能解释问题的消息之外什么都没改变.更有经验的人比我有希望认识一下这个调试消息无论是在我以前的代码(上下文意思此处所示)或我最新的代码,如下图所示.
原始代码
import UIKit
class ViewController: UIViewController {
// MARK: Initialization
let points: Int = 10 // 80 25 …Run Code Online (Sandbox Code Playgroud)