在View中绘制折线图等,View更新需要重绘CAShapeLayer,再重新绘制前,使用以下方法可以删除原本的CAShapeLayer,亲测有效:
NSArray<CALayer *> *subLayers = self.VideoTopView.layer.sublayers;
NSArray<CALayer *> *removedLayers = [subLayers filteredArrayUsingPredicate:
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
return [evaluatedObject isKindOfClass:[CAShapeLayer class]];
}]];
[removedLayers enumerateObjectsUsingBlock:^(CALayer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj removeFromSuperlayer];
}];