我做了一些使用基于UIView的子类中的框架的CALayer绘图,我需要更新设备旋转时的行,但在traitCollectionDidChange,框架仍然保持旋转前的值。有没有办法在旋转后获取帧的更新值?UIView帧traitCollectionDidChange没有更新
我的绘图代码看起来是这样的,叫它traitCollectionDidChange的视图控制器:
func setup() {
layer.sublayers?.removeAll()
let xAxisLine = UIBezierPath()
xAxisLine.move(to: CGPoint(x: 100, y: frame.height))
xAxisLine.addLine(to: CGPoint(x: bounds.width, y: frame.height))
let xAxisLayer = CAShapeLayer()
xAxisLayer.path = xAxisLine.cgPath
xAxisLayer.lineWidth = 2
xAxisLayer.fillColor = UIColor.clear.cgColor
xAxisLayer.strokeColor = UIColor.black.cgColor
layer.addSublayer(xAxisLayer)
}
这一部分吸引我的自定义图表的X轴,但更重要的帧值是旋转之前从而整个图形不合适和大小。
从视图控制器,我把它叫做是:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
barView.setup()
}
请用你的'traitCollectionDidChange'实现更新这个问题。 –
我承认我不应该使用我的设置代码进行重绘,但目前我的工作重点是获取重绘框架的新值 –