[英]iOS- How to Hide/Show UITabBarController's tab bar with animation?
我對iOS的UITabBarController
的標簽欄有疑問。
我正在使用UITabBarController
來顯示一些視圖,但是我希望這些視圖以盡可能大的屏幕顯示。 是否可以隱藏選項卡欄,使其通常不顯示,直到用戶觸摸屏幕,然后選項卡欄(帶有動畫)才會顯示在底部。 然后,幾秒鍾后,如果不執行任何操作,則選項卡欄將再次消失,從而使視圖又回到全屏狀態?
這就是你展示它的方式
- (void)showTabBar:(UITabBarController *)tabbarcontroller
{
tabbarcontroller.tabBar.hidden = NO;
[UIView animateWithDuration:kAnimationInterval animations:^{
for (UIView *view in tabbarcontroller.view.subviews) {
if ([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y-49.f, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height-49.f)];
}
}
} completion:^(BOOL finished) {
//do smth after animation finishes
}];
}
...這就是你隱藏它的方式
- (void)hideTabBar:(UITabBarController *)tabbarcontroller
{
[UIView animateWithDuration:kAnimationInterval animations:^{
for (UIView *view in tabbarcontroller.view.subviews) {
if ([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+49.f, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height+49.f)];
}
}
} completion:^(BOOL finished) {
//do smth after animation finishes
tabbarcontroller.tabBar.hidden = YES;
}];
}
使用已接受的答案,在iOS 7上,當您隱藏選項卡欄並再次顯示時,尺寸是錯誤的。 這段代碼給出了更好的結果:
- (void) toggleTabBar: (UITabBar *)tabBar view: (UIView*) view {
tabBar.hidden = NO;
[UIView animateWithDuration:0.5 animations:^{
if (hiddenTabBar) {
tabBar.center = CGPointMake(tabBar.center.x, self.view.window.bounds.size.height-tabBar.bounds.size.height/2);
}
else {
tabBar.center = CGPointMake(tabBar.center.x, self.view.window.bounds.size.height+tabBar.bounds.size.height);
}
} completion:^(BOOL finished) {
hiddenTabBar = !hiddenTabBar;
tabBar.hidden = hiddenTabBar;
}];
}
別認為這適用於Apple的UIGuidelines。 您正在使用的視圖繪制在選項卡欄的上方,因此,如果將其淡入淡出,將一無所有。
您可以用按鈕代替您所需要的選項卡欄來制作一個小視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.