2015-08-20 23 views
1

我試圖在地圖應用中複製效果,通過該效果,即使在iOS 7上,觸摸地圖也會滑落,然後再次沿頂部和底部的酒吧以及狀態欄當然也可以在我自己的應用中使用iOS 8。 當然,我在滑動我的工件時沒有任何問題,但狀態欄讓我感到困惑,我無法在iOS 8上滑動它,在iOS 7上也不會滑動。我可能達到的最好效果是通過重寫偏好狀態欄隱藏;當然,這並不適合一般的滑動運動。在地圖應用中複製Apple效果滑動狀態欄

怎麼可能做到呢?

回答

0

這是我控制感謝湯米的提示爲最終實現:

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來固定它,所以在滑動時跟隨吧。

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]; 
    } 
+0

這非常有趣。我不知道我可以將狀態欄視爲正常窗口。 –