ios sub view appears upside down in simulator

允我心安 提交于 2019-12-12 04:08:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!