Open RCCoop opened 1 year ago
Thank you for your commit. It very useful for me to develop with DGCharts on Mac!
It's strange that your PR fixing the bug has not been merged for a long time.
@liuxuan30 Hi, I found the same issue with Marker View and xib on Mac when I was developing. #5023
Issue Link :link:
https://github.com/danielgindi/Charts/issues/5023
Goals :soccer:
Make
MarkerView
work in MacOS, and add an example of it into the MacOS sample app.Implementation Details :construction:
MarkerView
didSet
inchartView
property, which calls a new functiondidAddToChart(_:)
.didAddToChart(_:)
only does anything in OSX. It adds theMarkerView
as an off-screen subview of thechartView
's containing view. This is necessary because theMarkerView
would not render in OSX without it having been added to a view already. See this SO answer for more context.viewFromXib(in:)
to returnSelf
rather thanMarkerView
so that subclasses will return as their own type rather than the base class.viewFromXib(in:)
to find the first instance ofSelf
in the loaded objects from the xib rather than assuming that the first object in that array was the one we'd be looking for. In MacOS this was a problem because the view was often second in the xib's loaded objects rather than the first.viewFromXib(in:)
, setwantsLayer
to true for the resulting view, which was also necessary to render the view duringdraw(context:point:)
as referenced in previous StackOverflow answer.Testing Details :mag:
RadarMarkerViewMac
in the MacOS sample app, which is nearly identical to theRadarMarkerView
in the iOS sample app.RadarMarkerViewMac
as the marker in the MacOS sample'sRadarDemoViewController
.RadarDemoViewController
displayed the marker as expected.