Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法获取CAShapeLayer的正确中心_Ios_Swift3_Cashapelayer - Fatal编程技术网

Ios 无法获取CAShapeLayer的正确中心

Ios 无法获取CAShapeLayer的正确中心,ios,swift3,cashapelayer,Ios,Swift3,Cashapelayer,有人能指出我做错了什么吗?我需要适应所有的iphone屏幕。这是一个好方法吗 var progressCircle = CAShapeLayer() let centerPoint = CGPoint (x: vu_SubmissionViewWithImageInCenter.bounds.width / 2, y: imgVu_Submission.bounds.width / 2) let circleRadius : CGFloat = vu_SubmissionVie

有人能指出我做错了什么吗?我需要适应所有的iphone屏幕。这是一个好方法吗

var progressCircle = CAShapeLayer()

    let centerPoint = CGPoint (x: vu_SubmissionViewWithImageInCenter.bounds.width / 2, y: imgVu_Submission.bounds.width / 2)
    let circleRadius : CGFloat = vu_SubmissionViewWithImageInCenter.bounds.width / 2 * 0.94

    let circlePath = UIBezierPath(arcCenter: centerPoint, radius: circleRadius, startAngle: CGFloat(-0.5 * M_PI), endAngle: CGFloat(1.5 * M_PI), clockwise: true    )

    progressCircle = CAShapeLayer ()
    progressCircle.path = circlePath.cgPath
    progressCircle.strokeColor = UIColor.fuschia.cgColor
    progressCircle.fillColor = UIColor.clear.cgColor
    progressCircle.lineWidth = 3.5
    progressCircle.strokeStart = 0
    progressCircle.strokeEnd = 1.0
    vu_SubmissionViewWithImageInCenter.layer.addSublayer(progressCircle)


    let animation = CABasicAnimation(keyPath: "strokeEnd")
    animation.fromValue = 0
    animation.toValue = 1.0
    animation.duration = 5.0
    animation.fillMode = kCAFillModeForwards
    animation.isRemovedOnCompletion = false
    progressCircle.add(animation, forKey: "ani")
    animation.delegate = self

您的半径计算错误。计算从弧中心到imageview边的距离,并将其用作半径

您的问题中包含代码的方法是什么?@robmayoff ViewWillLayoutSubview是视图控制器视图的子视图。在IB中,我检查了两次。您是否考虑过方法名称
viewWillLayoutSubviews
与方法
viewDidLayoutSubviews
相比意味着什么?问题不在于半径,而在于绘图中心