如何在隐藏UITabBar时添加观察者(通过'hides-bottom-bar-when-pushing')?我有一个自定义按钮位于我的标签栏下面,我想确保在隐藏UITabBar时它不会出现。谢谢!
答案 0 :(得分:4)
尝试使用UINavigationControllerDelegate protocol:
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if (viewController.hidesBottomBarWhenPushed) {
// ...
}
}
答案 1 :(得分:1)
最佳选择是将UIToolbar
放入已启用剪辑的UIView
内,并将剪辑视图放在UITabBar
正上方。然后将此UIView
添加为UITabBar
的子视图。以这种方式显示和隐藏UITabBar
会自动显示或隐藏您的UIToolbar
现在您可以设置UIToolbar
的显示和隐藏动画,并且每次UITabBar
时都会消失确实
答案 2 :(得分:-1)
这将告诉您该字段的值何时更改:
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.
}
}