Ios 确定UICollectionViewController/CollectionViewCell中CAShapeLayer类的CGRect值
我创建了一个swift文件,它添加了几个(CAShapeLayer)子层来显示图形元素。我已经用下面的代码成功地将它添加到UIViewController中,但是,我不知道如何将它添加到UICollectionViewController的单元格中。具体使用哪种代码以及如何获取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)
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)
}