Background ImageView is upside down(flipped) when I use CPTPGraphHostingView [Core plot]
Asked Answered
B

2

2

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.

Brainard answered 29/3, 2012 at 14:5 Comment(2)
possible duplicate of ios sub view appears upside down in simulatorDeibel
@EricSkroch Thanks I got the solution from your answer in the link you mentioned.Brainard
B
4

References for this answer:

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:

  1. Add two Views to your xib file, one of type CPTPGraphHostingView(for adding graph) and the other of type UIView(for adding any other ui controls, backgrounds etc). You can modify the type of View by modifying Class field under the heading Class Identity in View Identity tab of File's Owner window.
  2. Now add the graph to CPTPGraphHostingView and add other ui controls to the other view(UIView)
  3. 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.

Brainard answered 30/3, 2012 at 10:32 Comment(7)
"A very pathetic design approach though" - Seeing as how I designed this, I take offense to that comment. As I explain here, UIViews by default flip the coordinate system of CALayers contained within them. NSViews on the Mac and normal Quartz contexts do not flip this coordinate system. Therefore, in order to use the same rendering code on both Mac and iOS, one of the two needs to be inverted by Core Plot. Given that UIViews are the ones doing the flipping, we decided to invert that transformation on iOS so that it matched the Mac.Caskey
@BradLarson Ok, I am sorry, removed those comments.Brainard
I have added UIView and an image view inside it alongside CPTGraphHostingVIew in xib. But i only get to see the graph but not the view with image.Is the graph view overlapping with UIView? Where am i going wrong?Denunciate
@Denunciate I have updated my answer. This will solve your problem IABrainard
@djaqeel I've added those lines setting nil, but it doesn't affect the output. I added views as View(UIView)-> Image view(UIImageView) , Graph hosting view (CPTGraphHostingView)Denunciate
@TechnocraT, You have to add those lines right after initializing the graph. If you did the same, please visit this link https://mcmap.net/q/1042632/-core-plot-custom-themeBrainard
@djaqeel Dude I dint get you method working in my app but as i only had to add image i've done as follows: CPTImage* background = [[CPTImage alloc] initWithCGImage:[UIImage imageNamed:@"Myimage.png"].CGImage]; pieChart.plotAreaFrame.fill = [CPTFill fillWithImage:background]; But i still need to get it working the way you mentioned.Denunciate
M
0

Try self.view = (CPTPGraphHostingView *)view

Marv answered 29/3, 2012 at 14:10 Comment(1)
in which function? viewDidLoad?Brainard

© 2022 - 2024 — McMap. All rights reserved.