【发布时间】:2015-06-06 21:43:48
【问题描述】:
我正在尝试实现显示/隐藏标签栏效果,内容将被扩展以填充标签栏曾经所在的空间。
我找到了显示/隐藏标签栏的代码,我很满意(来源:http://www.developers-life.com/hide-uitabbarcontrolleruitabbar-with-animation.html)
我添加了以下代码来相应地定位我的按钮:
if (hiddenTabBar) {
self.constraintToBottom.constant=0;
[self.TestButton setNeedsUpdateConstraints];
} else {
self.constraintToBottom.constant=-49;
[self.TestButton setNeedsUpdateConstraints];
}
[self.TestButton layoutIfNeeded];
它按预期工作。除了按钮的动画。这是动画前应用的初始画面:
这是在动画之后
我可以成功隐藏标签栏并使用正确的动画定位按钮。但是,当我想再次显示选项卡栏时,按钮似乎从屏幕的底部(外部)开始,而不是第二张图中所示的位置。我已经调整了动画时间,以便在制作动画时可以捕捉屏幕:
以下是我隐藏/显示标签栏操作的完整代码
- (IBAction)TestTapped:(id)sender {
[UIView beginAnimations:nil context:NULL];
if(hiddenTabBar)
[UIView setAnimationDuration:60];
else
[UIView setAnimationDuration:0.5];
for(UIView *view in self.tabBarController.view.subviews)
{
CGRect _rect = view.frame;
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
_rect.origin.y = 431;
[view setFrame:_rect];
} else {
_rect.origin.y = 480;
[view setFrame:_rect];
}
} else if(view==self.TestButton)
{
NSLog(@"ZZ");
}
else{
if (hiddenTabBar) {
_rect.size.height = 431;
[view setFrame:_rect];
} else {
_rect.size.height = 480;
[view setFrame:_rect];
}
}
}
if (hiddenTabBar) {
self.constraintToBottom.constant=0;
[self.TestButton setNeedsUpdateConstraints];
} else {
self.constraintToBottom.constant=-49;
[self.TestButton setNeedsUpdateConstraints];
}
[self.TestButton layoutIfNeeded];
[UIView commitAnimations];
hiddenTabBar =!hiddenTabBar;
}
我希望按钮的动画从我的第二个图表的确切位置开始。
【问题讨论】:
标签: animation ios7 autolayout show-hide uitabbar