ios子视图在模拟器中颠倒

我已经在uiview子类中创build了一个活动指示器和一个标签,并在许多不同的标签中调用它。它在除了图表托pipe视图(CPTGraphHostinView)之外的大多数地方都按照预期工作。 在这个特定的视图中,子视图看起来是倒过来的。标签在旋转之上。我试图用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]; 

在这里输入图像说明

您不应该添加其他视图作为Core Plotgraphics托pipe视图的子视图。 正如您发现的那样,它会对其内容应用翻转转换,以便在OS X和iOS版本之间共享相同的绘图代码。

相反,让你的微调主机视图的兄弟(即,使他们同一父母的子视图)。

你应该使用转换只在x方向上翻转它

只需做到这一点:

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

这应该工作正常:)

你的应用程序是否支持设备的旋转? 这可能是导致这个问题的原因。 尝试设置自动化掩码UIViewAutoresizingNone

希望这个帮助

是的,这取决于你如何初始化你的ActivityIndicator即取决于它的框架。 因为,活动指标视图显示在中心。 但是对于UILabel,你已经确定了位置。 所以如果ActivityIndicator的框架很大,显然活动指标视图会在UILabel下面。