【问题标题】:Reproducing Apple effects in the map app sliding the Status Bar在地图应用中通过滑动状态栏再现 Apple 效果
【发布时间】:2015-11-14 12:58:31
【问题描述】:

我正在尝试在地图应用程序中复制效果,通过触摸地图在顶部和底部栏以及状态栏上再次滑动,即使在 iOS 7 上,当然也在我自己的应用程序中的 iOS 8 上. 当然,我在滑动我的工件时没有任何问题,但是状态栏让我感到困惑,我无法让它在 iOS 8 上滑动,更不用说在 iOS 7 上滑动了。我可能达到的最好方法是通过覆盖 prefersStatusBarHidden;一般的滑动运动当然不适合什么。

怎么可能呢?

【问题讨论】:

    标签: ios ios7 ios8 statusbar ios7-statusbar


    【解决方案1】:

    你可以这样做:

       UIWindow *statusBarWindow = (UIWindow *)[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
        if([statusBarWindow isKindOfClass:[UIWindow class]]){
            CGRect frame = statusBarWindow.frame;
            if(frame.origin.y < 0){
                frame.origin.y = 0;
            }
            else{
                frame.origin.y = -20;
            }
    
            [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                statusBarWindow.frame = frame;
            } completion:nil];
        }
    

    【讨论】:

    • 这很有趣。我不知道我可以将状态栏视为普通窗口。
    【解决方案2】:

    感谢 Tommy 的提示,这是我对控件的最终实现:

    BOOL controlsWereShown=YES;
    
    -(void)toggleControls{
        UIWindow *statusBarWindow = (UIWindow *)[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
        CGRect frame=CGRectZero;
        if([statusBarWindow isKindOfClass:[UIWindow class]]){
            frame= statusBarWindow.frame;
            if(frame.origin.y < 0){
                frame.origin.y = 0;
            }
            else{
                frame.origin.y = -85;
            }
         }
        [UIView animateWithDuration:.8 animations:^{
             self.barConstraint.constant=(controlsWereShown?-85:19);
             self.bottomConstraint.constant=(controlsWereShown?50:0);
             self.renewalViewConstraint.constant=(controlsWereShown?-120:0);
             controlsWereShown=!controlsWereShown;
             if (frame.size.width != 0) statusBarWindow.frame = frame;
             [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate) withObject:nil];
             [self.view layoutIfNeeded];
         }
                    completion :^(BOOL finished){
    
                    }
         ];
    }
    

    该解决方案中的唯一问题是状态栏与顶部栏一起滑动,而不是在滑动时保持附着在顶部。我通过将结束原点设置为 -85 而不是 -20 来修复它,以便在滑动时跟随杆。

    【讨论】:

      猜你喜欢
      • 2014-09-08
      • 2013-10-03
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-06
      • 2018-03-24
      相关资源
      最近更新 更多