简单实现Tabbar的隐藏显示动画 By H罗

简单实现Tabbar的隐藏显示动画

Hide Tabbar Controller with Animation

- (void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated {
    // bail if the current state matches the desired state
    if ([self tabBarIsVisible] == visible) return;
    
    // get a frame calculation ready
    CGRect frame = self.tabBarController.tabBar.frame;
    CGFloat height = frame.size.height;
    CGFloat offsetY = (visible)? -height : height;
    
    // zero duration means no animation
    CGFloat duration = (animated)? 0.3 : 0.0;
    
    [UIView animateWithDuration:duration animations:^{
        self.tabBarController.tabBar.frame = CGRectOffset(frame, 0, offsetY);
    }];
}

 

判断tabBar当前状态

// know the current state
- (BOOL)tabBarIsVisible {
    return self.tabBarController.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame);
}

 

//调用

- (void)buttonClick{
    [self setTabBarVisible:![self tabBarIsVisible] animated:YES];
}

 

Stackoverflow

 

 
posted @ 2015-05-22 17:27  sixindev  阅读(600)  评论(0编辑  收藏  举报