如何在iOS中的其他视图后面添加视图

我想在我的标签栏模拟在iOS中添加一个视图,然后显示它后面的animation。 但是,当我使用我的代码,必须来自我的标签栏后面的视图重叠我的标签栏一段时间。

标签栏以及显示何时按下标签栏按钮的视图

这是我的代码:

- (void)handlePressedButton { if (pressedButton.selected) { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; CGAffineTransform transform1 = CGAffineTransformMakeTranslation(-196.0, 0.0); CGAffineTransform transform2 = CGAffineTransformMakeTranslation(0.0, 0.0); [leftPanelView setTransform:transform1]; [movedView setTransform:transform2]; [UIView commitAnimations]; pressedButton.selected = NO; } else { pressedButton.selected = YES; if (leftPanelView) { [leftPanelView removeFromSuperview]; leftPanelView = nil; } CGRect viewFrame = CGRectMake(-196, 0, 236, 748); leftPanelView = [[UIView alloc] initWithFrame:viewFrame]; leftPanelView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"left-nav-content.png"]]; // Code to populate leftPanelView according to what button is pressed. [self populateLeftPanelView]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; [self.view addSubview:leftPanelView]; CGAffineTransform transform1 = CGAffineTransformMakeTranslation(236.0, 0.0); CGAffineTransform transform2 = CGAffineTransformMakeTranslation(112.0, 0.0); [leftPanelView setTransform:transform1]; [movedView setTransform:transform2]; [UIView commitAnimations]; } 

}

这里的leftPanelView是必须在标签栏下的视图。 移动视图是另一个视图,即在左侧面板的右侧(不介意)

尝试sendSubviewToBack

 [self.view sendSubviewToBack:leftPanelView]; 

除了addSubview之外,还有其他方法可以用来添加视图:

 – insertSubview:aboveSubview: – insertSubview:belowSubview: – insertSubview:atIndex: 

您可以使用这些方法控制视图的索引(实际上是z索引或图层顺序)。

哦,我自己find了解决办法。 我在这之后补充道:

 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; [self.view addSubview:leftPanelView]; 

这一行:

 [self.view sendSubviewToBack:leftPanelView];