【问题标题】:How to mimic the resizable StatusBar in the Spotify iOS app如何在 Spotify iOS 应用程序中模仿可调整大小的状态栏
【发布时间】:2011-12-05 00:21:26
【问题描述】:

我一直在努力弄清楚当应用进入离线模式时 Spotify 如何创建 UI。他们使StatusBar 看起来像是调整了大小,但实际上他们只是在下面放了一个视图,并调整了整个应用程序中所有控制器的大小。我试过子类化UINavigationController、子类化UIWindow、调整窗口大小,但似乎没有什么适合每种情况。

关于 Spotify 应用程序的有趣之处在于,当 iOS 自己的 UIViewController 子类以模态方式呈现时,他们的解决方案似乎仍然有效(如下图所示,显示了苹果的 MFMailComposeViewController - 你可以看出它不是由于 UIBarButtonItems 的自定义控制器)。

如果有人对这怎么可能有任何见解,那就太棒了。

【问题讨论】:

    标签: iphone ios uiview uiviewcontroller statusbar


    【解决方案1】:

    这是一件非常危险的事情。我过去做过,我做噩梦。下面是适用于 iOS4 并支持方向更改的代码。

    - (void) _adjustViewControllerforTicker {
        TickerView* vv = [ApplicationContext getTickerView];
        if ([PreferenceDataModel isFxTickerOn]&& self.navigationController.view.frame.origin.y==0) {
    
        CGRect tableRect = self.tableView.frame;
        self.tableView.frame = CGRectMake(tableRect.origin.x,tableRect.origin.y, tableRect.size.width, tableRect.size.height -20);
        UINavigationController *nav = self.navigationController;
        CGRect gframe = CGRectOffset(self.navigationController.view.frame, 0, 20);
        self.navigationController.view.frame = gframe;
        if (!vv) {
            vv = [[TickerView alloc] initWithFrame:CGRectMake(0, 0, 480, 20)];
    
            [nav.view addSubview:vv];
            [vv release];
            self.tableView.contentInset=UIEdgeInsetsMake(0,0,20.0,0.0);
            [ApplicationContext setTickerView:vv];
        }
    
        if (![PreferenceDataModel isTickerOn]) {
            self.tableView.contentInset= UIEdgeInsetsZero;
            if (vv){
               [vv removeFromSuperview];
               vv=nil;
               [ApplicationContext setTickerView:nil];
        }
    }
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation          { 
        [self _adjustViewControllerforTicker];
    }
    
    - (void) viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
      [self _adjustViewControllerforTicker];
      TickerView* vv = [ApplicationContext getTickerView];
      if ([vv count]) {
        [vv startAnimation];
      }
    }
    
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [self _adjustViewControllerforTicker];
    }
    

    这就是它的外观:

    【讨论】:

    • 我很好奇,当您呈现模态视图控制器时,您的“ticker”是否仍然位于所有内容之上?我已经尝试过你在做什么(调整 NavigationController 的视图)。
    • 我的代码被添加到 UINavigationController 级别,所以即使你切换 UIViewControllers 也会持续存在。你可以用同样的方式调整你的模态 uiViewController,这样你就会得到想要的效果。
    • 您能否详细说明“噩梦”?
    猜你喜欢
    • 2013-09-29
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多