2017-07-03 44 views
1

我有這樣的代碼:隱藏導航欄和工具欄的Safari風格

#pragma mark - UIScrollViewDelegate Methods 

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView 
{ 
    self.lastOffsetY = scrollView.contentOffset.y; 
} 

- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView 
{ 
    if (self.canAnimateBars) 
     [self animeteBars:scrollView]; 
} 

- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 
{ 
    if(self.canAnimateBars) 
     [self animeteBars:scrollView]; 
} 

-(void)animeteBars:(UIScrollView *)scrollView { 
    bool hide = (scrollView.contentOffset.y > self.lastOffsetY); 

    [self.view layoutIfNeeded]; 

    if (hide) 
     self.quickLinkToolBarBotom.constant = -44.0; 
    else 
     self.quickLinkToolBarBotom.constant = 0.0; 

    [[self navigationController] setNavigationBarHidden:hide animated:YES]; 
} 

#pragma mark - UIWebViewDelegate Methods 

- (void)webViewDidFinishLoad:(UIWebView *)webView { 
    self.canAnimateBars = YES; 
} 

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { 
    NSLog(@"Error: %@", error.localizedDescription); 
} 

它好的工作,但想歸檔Safari的動畫相同的行爲。

我已經試過這個庫AMScrollingNavbar,但我不能讓它與工具欄一起工作。

在Safari瀏覽器中滾動Web視圖時,如何進行移動條的計算。

感謝您的幫助。

回答

0

您可以使用此代碼。我認爲這個代碼適合你。

-(void)animeteBars:(UIScrollView *)scrollView { 

    bool hide = (scrollView.contentOffset.y > self.lastOffsetY); 

    [self.view layoutIfNeeded]; 
    CGFloat duration = 0.3; 

    if (hide) 
    { 
     [UIView animateWithDuration:duration animations:^{ 
      self.quickLinkToolBarBotom.constant = -44.0; 
     } completion:nil]; 

    } 
    else 
    { 
      [UIView animateWithDuration:duration animations:^{ 
      self.quickLinkToolBarBotom.constant = 0.0; 
     } completion:nil]; 
    } 
    [[self navigationController] setNavigationBarHidden:hide animated:YES]; 
} 
+0

感謝您的幫助,但這並不像Safari那樣存檔,您的代碼和我的代碼一樣 –