簡體   English   中英

觀察 UITabBar 何時對 Delegate 隱藏

[英]Observe when UITabBar is Hidden from Delegate

如何在隱藏 UITabBar 時添加觀察者(通過“hides-bottom-bar-when-pushed”)? 我的標簽欄下方有一個自定義按鈕,我想確保在隱藏 UITabBar 時它不會出現。 謝謝!

嘗試使用UINavigationControllerDelegate 協議

- (void)navigationController:(UINavigationController *)navigationController 
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if (viewController.hidesBottomBarWhenPushed) {
        // ...
    }
}

最好的選擇是將您的UIToolbar放在啟用了剪輯的UIView中,並將 position 放在UITabBar上方的剪輯視圖中。 然后將此UIView添加為您的UITabBar的子視圖。 這種顯示和隱藏UITabBar的方式將自動顯示或隱藏您的UIToolbar現在您可以為UIToolbar的顯示和隱藏設置動畫,並且每次UITabBar執行時它仍然會消失。

這將告訴您該字段的值何時更改:

 UITabBar *myTabBar = [[UITabBar alloc] init];

 [self addObserver:myInterestedObjectWhoWantsToKnowWhenTabBarHiddenChanges
        forKeyPath:@"myTabBar.hidesBottomBarWhenPushed"
           options:NSKeyValueObservingOptionNew
           context:nil];

然后在 myInterestedObjectWhoWantsToKnowWhenTabBarHiddenChanges.m 中,實現

     - (void)observeValueForKeyPath:(NSString *)keyPath 
                  ofObject:(id)object 
                    change:(NSDictionary *)change
                   context:(void *)context {    

               if ([keyPath isEqualToString:@"myTabBar.hidesBottomBarWhenPushed"]) {  // this key must match, where observer is set.        
                    // object will be "self" from the code above
                    // and the change dictionary will have the old and new values.
               }
       } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM