Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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 确定UICollectionViewController/CollectionViewCell中CAShapeLayer类的CGRect值_Ios_Swift_Xcode - Fatal编程技术网

Ios 确定UICollectionViewController/CollectionViewCell中CAShapeLayer类的CGRect值

Ios 确定UICollectionViewController/CollectionViewCell中CAShapeLayer类的CGRect值,ios,swift,xcode,Ios,Swift,Xcode,我创建了一个swift文件,它添加了几个(CAShapeLayer)子层来显示图形元素。我已经用下面的代码成功地将它添加到UIViewController中,但是,我不知道如何将它添加到UICollectionViewController的单元格中。具体使用哪种代码以及如何获取CGRect帧坐标/如何查询单元格的实际宽度和高度 override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated)

我创建了一个swift文件,它添加了几个(CAShapeLayer)子层来显示图形元素。我已经用下面的代码成功地将它添加到UIViewController中,但是,我不知道如何将它添加到UICollectionViewController的单元格中。具体使用哪种代码以及如何获取CGRect帧坐标/如何查询单元格的实际宽度和高度

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let width: CGFloat = 100.0
    let height: CGFloat = 100.0

    let chart = chordChart(frame: CGRect(x: self.view.frame.size.width/2 - width/2,
                                         y: self.view.frame.size.height/2 - height/2,
                                         width: width,
                                         height: height))

    self.view.addSubview(chart)
}

//以下是上述swift文件的开头(UiView-由UIBezierPath和CAShapeLayer变量组成):


以下是swift文件的开头(UiView-由UIBezierPath和CAShapeLayer变量组成):以下是swift文件的开头(UiView-由UIBezierPath和CAShapeLayer变量组成):
import UIKit

class chordChart: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)

        self.backgroundColor = UIColor.white

        formatChordDisplay()

    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }