How do I add an observer for when a UITabBar is hidden (through 'hides-bottom-bar-when-pushed')? I have a custom button that sits underneath my tab bar an开发者_StackOverflow社区d I want to make sure it doesn't appear when the UITabBar is hidden. Thanks!
Try using the UINavigationControllerDelegate protocol:
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if (viewController.hidesBottomBarWhenPushed) {
// ...
}
}
The best option is to place your UIToolbar
inside a UIView
that has clipping enabled and position the clip-view just above the UITabBar
. Then add this UIView
as a subview of your UITabBar
. This way showing and hiding the UITabBar
will automatically show or hide your UIToolbar
Now you can animate the showing and hiding of your UIToolbar
and still have it disappear each time the UITabBar
does.
This will tell you when the value of that field changes:
UITabBar *myTabBar = [[UITabBar alloc] init];
[self addObserver:myInterestedObjectWhoWantsToKnowWhenTabBarHiddenChanges
forKeyPath:@"myTabBar.hidesBottomBarWhenPushed"
options:NSKeyValueObservingOptionNew
context:nil];
Then in myInterestedObjectWhoWantsToKnowWhenTabBarHiddenChanges.m, implement
- (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.
}
}
精彩评论