- (void)drawRect:(CGRect)rect
is just enough to set [_chartView setContentMode:UIViewContentModeRedraw]
and this method will be called when device changes it's orienatation and it's possible to calculate f.e. new center point for my chart.- (id)initWithFrame:(CGRect)frame
and then add it in view controller like [self.view addSubview:chartView];
. How in this case I can handle rotation to redraw my chart?To make your chart rendered correctly when device orientation changes you need to update chart's layout, here is the code that you should add to your view controller:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_chartView.frame = self.view.bounds;
[_chartView strokeChart];
}