系统自带的显示和隐藏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"];
}
}