[英]Improve tabBar animation when hidden
我考慮過如何使tabBar的隱藏動畫更加優雅和流暢:
這是我的實現方式:
所以我只想改善動畫,而tabBar突然消失,消失並隱藏。
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self.tabBarController.tabBar setHidden:YES];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self.tabBarController.tabBar setHidden:NO];
}
有什么建議嗎?
嘗試添加此方法:
- (void)setTabBarHidden:(BOOL)tabBarHidden animated:(BOOL)animated
{
if (tabBarHidden == _isTabBarHidden)
return;
CGFloat offset = tabBarHidden ? self.tabBarController.tabBar.frame.size.height : -self.tabBarController.tabBar.frame.size.height;
[UIView animateWithDuration:animated ? 0.6 : 0.0
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:0.5
options:UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionLayoutSubviews
animations:^{
self.tabBarController.tabBar.center = CGPointMake(self.tabBarController.tabBar.center.x,
self.tabBarController.tabBar.center.y + offset);
}
completion:nil];
_isTabBarHidden = tabBarHidden;
}
然后,您可以像[self setTabBarHidden:YES animated:YES]
和[self setTabBarHidden:NO animated:YES]
一樣調用它來隱藏和顯示您的條,這會將其移入和移出屏幕,而不僅僅是立即消失。
不要忘了添加一個新的bool屬性isTabBarHidden
,您還可以播放動畫的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.