0

I have created an activity indicator and a label below it in a uiview sub class and calling it in many different tabs.It works as intended in most of the places i'm calling it except in Graph Hosting views(CPTGraphHostinView). In this particular view the subView appears to be upside down.The label goes above the spinner.I tried with imageview instead of label, and its the same upside down image.

Here is my initWithframe method

- (id)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
       // Initialization code.

        NSLog(@"AI: init with frame");

    spinnerView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    spinnerView.center = self.center;       
    [self addSubview:spinnerView];

    UILabel* loadingMsg = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 90.0f, 30.0f)];
    loadingMsg.center =  CGPointMake(spinnerView.center.x , spinnerView.center.y + spinnerView.bounds.size.height/2 +10);
    loadingMsg.textAlignment = UITextAlignmentCenter;
    loadingMsg.backgroundColor = [UIColor clearColor];
    loadingMsg.text = @"loading";
    [self addSubview:loadingMsg];


}
    return self;
}

Here is the call to activityIndicator in view did load

ob_activityobject = [[ActivityIndicator alloc] initWithFrame:self.view.bounds];

    [ob_activityobject showInView:self.view];

enter image description here

TechnocraT
  • 313
  • 2
  • 6
  • 22

4 Answers4

5

You should not add other views as subviews of a Core Plot graph hosting view. As you've discovered, it applies a flip transform to its contents so the same drawing code can be shared between the OS X and iOS versions.

Instead, make your spinner a sibling of the hosting view (i.e., make them subviews of the same parent).

Eric Skroch
  • 27,381
  • 3
  • 29
  • 36
  • But iam also adding a label below the spinner, how do i do that? And is it that such output appears in simulator only or will it be flip transformed on the device as well? – TechnocraT Feb 29 '12 at 06:50
  • I have applied self.transform and the label is now readable but still its above the spinner. I do not know how to implement what you said i.e make the subview of same parent.Can you direct me to some examples. Thanks. – TechnocraT Mar 01 '12 at 04:33
  • +1 Thanks, this worked. I added to UIViews to xib file, one is normal UIView and the other is CPTGraphHostingView. I added all my controls/background images etc to UIView. This is working like a charm. Thanks –  Mar 30 '12 at 07:08
1

You should use transformation to flip it in x direction only

Simply do this:

loadingMsg.layer.transform = CATransform3DMakeRotation(M_PI, 1, 0, 0);
spinnerView..layer.transform = CATransform3DMakeRotation(M_PI, 1, 0, 0);

This should work fine :)

Botz3000
  • 39,020
  • 8
  • 103
  • 127
Bhupendra
  • 2,525
  • 18
  • 20
0

Did your application support rotation of the device? It might this which causes this issue. Try setting autresizing mask to UIViewAutoresizingNone

Hope this help

Ganzolo
  • 1,394
  • 12
  • 23
0

Yes, it depends how you are initializing your ActivityIndicator i.e., depends on its frame. Because, activity indicator view is shown at center. But for UILabel, you have fixed the position. So if the frame is large for ActivityIndicator, obviously the activity indicator view will come below the UILabel.

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55