从委托中隐藏UITabBar时观察

时间:2011-06-02 22:37:42

标签: iphone objective-c cocoa-touch ios

如何在隐藏UITabBar时添加观察者(通过'hides-bottom-bar-when-pushing')?我有一个自定义按钮位于我的标签栏下面,我想确保在隐藏UITabBar时它不会出现。谢谢!

3 个答案:

答案 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.
               }
       } 
相关问题