这段代码使用EasyPeasy库创建我的自定义视图
override func viewDidLoad() {
super.viewDidLoad()
chart = Init( ChartView(frame: .zero, with: calc)) {) {
$0.translatesAutoresizingMaskIntoConstraints = false
}
view.addSubview(chart)
chart <- [
Top(0).to(self.topLayoutGuide),
Bottom(0),
Left(0),
Right(0)
]
chart.layoutIfNeeded()
}
但是如果我旋转一个设备,我的自定义视图不会重新加载:它只是不正确地缩放(例如,圆圈变成椭圆形)。但是如果我使用chart.layoutIfNeeded()
手动重绘,它工作得很好。有没有办法说:“请,亲爱的设备,每次我改变我的视图的框架/旋转时,重新绘制我的自定义视图”?P.S. EasyPeasy使用NSLayoutConstraint
。https://github.com/nakiostudio/EasyPeasy
发布于 2016-10-10 15:06:46
我发现这解决了我的问题:
chart = Init( ChartView(frame: .zero, with: calc)) {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.contentMode = .redraw
}
我的意思是视图需要这个方法:setNeedsDisplay()
。要由操作系统自动执行此操作,需要设置chart.contentMode = .redraw
。
https://stackoverflow.com/questions/39958999
复制