[英]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.