I have a project using autolayout,
And I notice that after a viewWillAppearcouple viewWillLayoutSubViewsthey viewDidLayoutSubViewswill be called several times on iOS 8, for my case it is usually 2-3 times.
The fist viewDidLayoutSubViewswill get the wrong frame size, so I need to avoid the first viewDidLayoutSubViewsone and then turn on my views again.
However, when I tested it on iOS 7, I found that only one pair was called viewWillLayoutSubViewsand viewDidLayoutSubViewstherefore my code broke again.
My question is: what has changed on iOS 8 for this behavior?
EDIT: I inserted the demo code here:
In the code, _pieChart will be added to self.ChartViewCanvas and self.ChartViewCanvas will use autostart. _pieChart is the old project code that is drawn without an automatic layout.
I needed to draw a pie chart in front of viewDidAppear, because drawing in viewDidAppear would have a 1 second delay compared to other views in the storyboard. This is not allowed for me.
Is there any way to know when the last one viewDidLayoutSubViews? A call [self.ChartViewCanvas addSubview:_pieChart];several times will lead to poor performance, and sometimes _pieChart drawInRect will not be called every time, so the chart does not update.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_pieChart.delegate = self;
if (!_pieChart) {
_pieChart = [[PieChartView alloc] initWithFrame:CGRectMake(0, 0, pieRadius * 2, pieRadius * 2)];
}else {
[_pieChart setFrame:CGRectMake(0, 0, pieRadius * 2, pieRadius * 2)];
}
if ([_pieChart superview]) {
[_pieChart removeFromSuperview];
}
[self.ChartViewCanvas addSubview:_pieChart];
}