2017-05-31 7 views
0

は現在、私は私がtableViewは正確にhighestView下になることを意味しているスクロールダウンしたときにtopView dissappearをしたいと思いこれらの制約をプログラムで設定するにはどうすればよいですか?

--highestView-- 
--topView-- 
--tableView-- 

以下のように私のViewControllerを持っています。

スクロールすると、上のような元のビューに戻るようにします。

私のコードは以下の通りです: - 作品をスクロールダウンする

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

    CGFloat scrollPos = self.tableView.contentOffset.y ; 

    if(scrollPos >= self.currentOffset){ 
     //Fully hide your toolbar 
     [UIView animateWithDuration:2.25 animations:^{ 
      self.topView.hidden = YES; 
      self.topViewTopConstraint.active = NO; 
      self.theNewConstraint2.active = NO; 
      self.theNewConstraint = [NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.highestView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; 
      self.theNewConstraint.active = YES; 

     }]; 
    } else { 
     //Slide it up incrementally, etc. 
     self.theNewConstraint.active = NO; 
     self.topView.hidden = NO; 
     self.topViewTopConstraint.active = YES; 
     self.theNewConstraint2 = [NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; 
     self.theNewConstraint2.active = YES; 



     //self.topView.hidden = NO; 
    } 
} 

まさに私が欲しいが、上にスクロールすると、失敗したかのように。現在、topViewはスクロールアップ時にtableViewの後ろに表示されます。これをどうすれば解決できますか?

答えて

0

あなたのtopViewの高さcosntraintを設定し、それを非表示にする場合は0にしてください!

制約を適用するにはMasonryを調べてください。高さ制約を追加するための

[toppView mas_makeConstraints:^(MASConstraintMaker *make) { 
    make. mas_height.equalTo(100); //just make this 0 when you want to hide the topView 
}]; 
0

あなたはこの使用XIBの制約を達成することができます。
HeightView < - >TopView < - >TableViewVertical SpaceBottom Space制約に相互に接続されているこれら三つのビュー。

はその後TopViewに高さ制約を追加し、それがIBOutletだ作るよう:

@IBOutlet weak var topViewHeightCon: NSLayoutConstraint! 

そして、独自のコードを再利用することができますよう:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView { 
    CGFloat scrollPos = self.tableView.contentOffset.y; 
    if(scrollPos >= self.currentOffset){ 
    topViewHeightCon.constant = 0 
    UIView.animate(withDuration: 0.3, animations: { 
     self.view.layoutIfNeeded() 
    }) 
    } else { 
    topViewHeightCon.constant = originalHeight 
    UIView.animate(withDuration: 0.3, animations: { 
     self.view.layoutIfNeeded() 
    }) 
    } 
} 
関連する問題