ios sub view appears upside down in simulator
Asked Answered
I

4

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

Inorganic answered 28/2, 2012 at 9:15 Comment(1)
Now THAT is a funky one... :)Graciagracie
C
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).

Chowder answered 28/2, 2012 at 12:20 Comment(3)
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?Inorganic
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.Inorganic
+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. ThanksShape
G
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 :)

Goffer answered 19/6, 2012 at 11:1 Comment(0)
B
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

Burstone answered 28/2, 2012 at 9:21 Comment(2)
I tried self.autoresizingMask = UIViewAutoresizingNone; but its the sameInorganic
Try it on the label, not on self.Burstone
C
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.

Clarkclarke answered 28/2, 2012 at 9:23 Comment(1)
As i said, it works the way i want in all the views except for the graph hosting views..Inorganic

© 2022 - 2024 — McMap. All rights reserved.