iOS中如何显示和隐藏TabBar的动画效果
这篇文章给大家分享的是有关iOS中如何显示和隐藏TabBar的动画效果的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
系统自带的显示和隐藏tabBar是没有动画效果的,如何给它加上动画效果呢?
下面是示例代码:
//隐藏标签栏
- (void)hiddenTheTabBar
{
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isHiddenTabBar"]) {
for (UIView *v in [self.view subviews]) {
if ([v isKindOfClass:[UITabBar class]]) {
[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(){
CGRect frame = v.frame;
frame.origin.y += 49.0f;
v.frame = frame;
} completion:nil];
} else {
[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(){
CGRect frame = v.frame;
frame.size.height += 49.0f;
v.frame = frame;
} completion:nil];
}
}
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isHiddenTabBar"];
}
}
//显示标签栏
- (void)showTheTabBar
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isHiddenTabBar"]) {
for (UIView *v in [self.view subviews]) {
if ([v isKindOfClass:[UITabBar class]]) {
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(){
CGRect frame = v.frame;
frame.origin.y -= 49.0f;
v.frame = frame;
} completion:nil];
} else {
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(){
CGRect frame = v.frame;
frame.size.height -= 49.0f;
v.frame = frame;
} completion:nil];
}
}
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isHiddenTabBar"];
}
}
感谢各位的阅读!关于"iOS中如何显示和隐藏TabBar的动画效果"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!