ios子视图在模拟器中显示为倒置

时间:2012-02-28 09:15:42

标签: ios core-plot subview

我在uiview子类中创建了一个活动指示符和一个标签,并在许多不同的tab中调用它。除了Graph Hosting视图(CPTGraphHostinView)之外,它在我调用它的大多数地方都能正常工作。在这个特殊的视图中,subView看起来是颠倒的。标签位于微调器上方。我尝试使用imageview而不是标签,并使用相同的倒置图像。

这是我的initWithframe方法

- (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;
}

以下是对视图中的activityIndi​​cator的调用加载

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

    [ob_activityobject showInView:self.view];

enter image description here

4 个答案:

答案 0 :(得分:5)

您不应将其他视图添加为Core Plot图托管视图的子视图。正如您所发现的,它对其内容应用了翻转变换,因此可以在OS X和iOS版本之间共享相同的绘图代码。

相反,让你的微调器成为托管视图的兄弟(即,使它们成为同一父级的子视图)。

答案 1 :(得分:1)

您应该使用转换仅在x方向上翻转

只需这样做:

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

这应该可以正常工作:)

答案 2 :(得分:0)

您的应用是否支持设备轮换?这可能导致这个问题。尝试将autresizing mask设置为UIViewAutoresizingNone

希望这个帮助

答案 3 :(得分:0)

是的,这取决于您初始化ActivityIndicator的方式,即取决于其框架。因为,活动指示器视图显示在中心。但是对于UILabel来说,你已经确定了这个位置。因此,如果ActivityIndicator的框架很大,显然活动指示器视图将低于UILabel。