wzb*_*zon 44 iphone core-animation view ios
我想在iOS中的标签栏模拟下添加一个视图,然后用它后面的动画显示它.但是当我使用我的代码时,必须来自我的标签栏后面的视图会重叠我的标签栏一段时间.

这是我的代码:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
}
这里的leftPanelView是必须位于标签栏下的视图.移动视图是另一个视图,位于左侧面板的右侧(不要介意)
He *_*ing 119
此外addSubview,您可以依赖其他方法来添加视图:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– insertSubview:atIndex:
Run Code Online (Sandbox Code Playgroud)
您可以使用这些方法控制视图的索引(实际上是z-index或图层顺序).
ade*_*der 51
[self.view sendSubviewToBack:leftPanelView];
Run Code Online (Sandbox Code Playgroud)
xma*_*lov 12
在视图层次结构中的另一个视图下方插入视图:
view.insertSubview(subview1, belowSubview: subview2)
Run Code Online (Sandbox Code Playgroud)
在视图层次结构中的另一个视图上方插入视图:
view.insertSubview(subview1, aboveSubview: subview2)
Run Code Online (Sandbox Code Playgroud)
在指定的索引处插入子视图:
view.insertSubview(subview, at: index)
Run Code Online (Sandbox Code Playgroud)
移动指定的子视图,使其显示在其兄弟节点后面:
subview1.sendSubviewToBack(subview2)
Run Code Online (Sandbox Code Playgroud)
移动指定的子视图,使其显示在其兄弟节点之上:
subview1.bringSubviewToFront(subview2)
Run Code Online (Sandbox Code Playgroud)
在指定的索引处交换子视图:
view.exchangeSubview(at: index1, withSubviewAt: index2)
Run Code Online (Sandbox Code Playgroud)
哦,我自己找到了解决方案.我在此之后添加了:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
Run Code Online (Sandbox Code Playgroud)
这一行:
[self.view sendSubviewToBack:leftPanelView];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38665 次 |
| 最近记录: |