问题
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];
回答1:
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).
回答2:
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 :)
回答3:
Did your application support rotation of the device? It might this which causes this issue. Try setting autresizing mask to UIViewAutoresizingNone
Hope this help
回答4:
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.
来源:https://stackoverflow.com/questions/9479202/ios-sub-view-appears-upside-down-in-simulator