问题
I am using core plot 1.0 in my iphone app. All works fine, graphs are drawing perfectly, But I am facing a weird problem that All the controls on graph page(CPTPGraphHostingView) are mirrored.
Ie: On that xib file, I set the class in class Identity of top UIView to CPTPGraphHostingView, then problem arises.
Please help me how to solve this. The controls appear correctly in interface builder, but when I run the project all gets messed up.
Even I have tried to add background Image programatically, but that also is mirrored.
回答1:
References for this answer:
- Core plot google group
- Related SO question
I came to know that the whole CPTPGraphHostingView is inverted upside down to support both Mac OS and iOS. This is by design and is not a bug.
So the solution from the given links is that:
- Add two Views to your xib file, one of type
CPTPGraphHostingView(for adding graph) and the other of typeUIView(for adding any other ui controls, backgrounds etc). You can modify the type of View by modifyingClass fieldunder theheading Class IdentityinView Identity tabofFile's Owner window. - Now add the graph to CPTPGraphHostingView and add other ui controls to the other view(UIView)
- End of story
UPDATE: If you add CPTPGraphHostinView to interface, no other components will be visible, for that you'll have to set theme, and fill of CPTXYGraph to nil. Ie add following lines after you initialize your CPTXYGraph:
CPTTheme *theme = nil;
[barChart applyTheme:theme]; // barChart is my CPTXYGraph
barChart.fill = nil;
barChart.plotAreaFrame.fill = nil;
NOTE:: Add CPTPGraphHostingView such that it is child of top level UIView, and other components are in top level UIView, and CPTPGraphHostingView is above all other components.
回答2:
Try self.view = (CPTPGraphHostingView *)view
来源:https://stackoverflow.com/questions/9927031/background-imageview-is-upside-downflipped-when-i-use-cptpgraphhostingview-co