2016-06-23 10 views

答えて

9

テーブルビューをスクロールするときはいつでもスクロール可能なナビゲーションバーにはいくつかのgitライブラリを使うことができます/上から下/上から下へスクロールすると、自動的にナビゲーションバーが調整されます。

あなたはこの

スウィフト

override func viewWillAppear(animated: Bool) { 
    super.viewWillAppear(animated) 

    if let navigationController = self.navigationController as? ScrollingNavigationController { 
     navigationController.followScrollView(tableView, delay: 50.0) 
    } 
} 

目的のように使用するために、このコードのように、ここでこのライブラリを使用することができます - C

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    [(ScrollingNavigationController *)self.navigationController followScrollView:self.tableView delay:50.0f]; 
} 

それはすべて、この関連を管理するためのいくつかのデリゲートメソッドを助けましたスクロールとナビゲーション。

AMScrollingNavbar click here for see

enter image description here

私はこれがあなたのために有用であると考えています。

4

@property(非アトミック)CGFloat currentOffsetを作成します。

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

} 

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

    CGFloat scrollPos = self.collectionProductView.contentOffset.y ; 

    if(scrollPos >= _currentOffset){ 
     //Fully hide your toolbar 
     [UIView animateWithDuration:2.25 animations:^{ 
      [self.navigationController setNavigationBarHidden:YES animated:YES]; 

     }]; 
    } else { 
     //Slide it up incrementally, etc. 
     [self.navigationController setNavigationBarHidden:NO animated:YES]; 
    } 
} 

再び [self.navigationController setNavigationBarHidden:NOアニメーション:YES]を貼り付けることを忘れないでください。

at viewwilldisappearまたはコントローラが別のコントローラに移動しているときは、次のView Controllerナビゲーションバーが消える可能性があるため、別のコントローラに移動しているときはいつでも。

+0

ありがとうございます。それは私を働かせた。 – Raja

2
func scrollViewDidScroll(_ scrollView: UIScrollView) 
     { 
      // var navigationBarFrame = self.navigationController!.navigationBar.frame 
      let currentOffset = scrollView.contentOffset 

      if (currentOffset.y > (self.lastContentOffset?.y)!) { 
       if currentOffset.y > 0 { 
        initial = initial - fabs(CGFloat(currentOffset.y - self.lastContentOffset!.y)) 
       } 
       else if scrollView.contentSize.height < scrollView.frame.size.height { 
        initial = initial + fabs(CGFloat(currentOffset.y - self.lastContentOffset!.y)) 
       } 
      } 
      else { 
       if currentOffset.y < scrollView.contentSize.height - scrollView.frame.size.height { 
        initial = initial + fabs(CGFloat(currentOffset.y - self.lastContentOffset!.y)) 
       } 
       else if scrollView.contentSize.height < scrollView.frame.size.height && initial < maxPlus { 
        initial = initial - fabs(CGFloat(currentOffset.y - self.lastContentOffset!.y)) 
       } 
      } 

      if (initial <= maxMinus){ 
       initial = maxMinus 
       self.tableviewTopConstrin.constant = 0 
       UIView.animate(withDuration: 0.4, animations: { 
        self.view.layoutIfNeeded() 
       }) 

      }else if(initial >= maxPlus){ 
       initial = maxPlus 
       self.tableviewTopConstrin.constant = 70 
       UIView.animate(withDuration: 0.4, animations: { 
        self.view.layoutIfNeeded() 
       }) 
      }else{ 
      } 
      self.lastContentOffset = currentOffset; 
     } 
10

のiOS 8ので、あなただけの

self.navigationController?.hidesBarsOnSwipe = true 

使用することができますこれは、あなたのViewControllerがNavigationControllerに埋め込まれている、もちろん必要です。 NavigationControllerのすべての子VCはこの動作を継承しますので、viewWillAppearでそれを有効/無効にしたいと思うかもしれません。 ストーリーボードのナビゲーションコントローラでそれぞれのフラグを設定することもできます。 Screenshot of Navigation Controller in Storyboard

+0

魅力的な作品です! :) – Eironeia

関連する問題