【问题标题】:Observe when UITabBar is Hidden from Delegate观察 UITabBar 何时对 Delegate 隐藏
【发布时间】:2011-06-02 22:37:41
【问题描述】:

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

【问题讨论】:

    标签: iphone objective-c cocoa-touch ios


    【解决方案1】:

    尝试使用UINavigationControllerDelegate protocol

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

    【讨论】:

      【解决方案2】:

      最好的选择是将您的UIToolbar 放在启用了剪辑的UIView 中,并将剪辑视图放置在UITabBar 的正上方。然后将此UIView 添加为UITabBar 的子视图。通过这种方式显示和隐藏UITabBar 将自动显示或隐藏您的UIToolbar 现在您可以为UIToolbar 的显示和隐藏设置动画,并且每次UITabBar 执行时它仍然会消失。

      【讨论】:

      • UITabBarController 中的标签栏是只读的,怎么添加子视图呢?
      【解决方案3】:

      这会告诉你该字段的值何时发生变化:

       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.
                     }
             } 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-15
        • 1970-01-01
        • 1970-01-01
        • 2012-08-24
        • 2011-08-08
        相关资源
        最近更新 更多