title: Swift: change tableview height on scroll
body: <p>I have a VC as shown in the image<a href="https://i.stack.imgur.com/1k8O2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1k8O2.png" alt="enter image description here"></a></p>
  
  <p>It has a <strong>UICollectionView</strong> on top, and a <strong>UITableView</strong> at the bottom.
  CollectionView has 1:3 of the screen and TableView has 2:3 of the screen(set using equalHeight constraint).</p>
  
  <p>I want to <strong>change the height</strong> of the <strong>UICollectionView</strong> when the <strong>tableView is scrolled</strong>.</p>
  
  <p>When the <strong>tableView</strong> is <strong>scrolled up</strong>,I want to change the multiplier of equalHeights constraint to like 1:5 and 4:5 of collectionView and tableView respectively.This will ensure that <strong>height of tableView increases</strong> and <strong>collectionView decreases</strong></p>
  
  <p>When the <strong>tableView</strong> is <strong>scrolled down</strong>, the multiplier of equalHeights constraint should <strong>reset to default</strong>.</p>
  
  <p>I've tried adding swipe and pan gestures to tableView, but they are unrecognised.</p>
  
  <p>How to achieve this functionality?</p>
  
  <p>P.S: Would love to achieve this functionality by using a pan gesture, so that dragging up and down changes the heights progressively. </p>
  
  <p>This is the view hierarchy<a href="https://i.stack.imgur.com/A9zx9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A9zx9.png" alt="enter image description here"></a></p>
  
  <p><strong>EDIT/UPDATE</strong></p>
  
  <p>This is the code that I'm using.</p>
  
  <pre><code>class MyConstant {
      var height:CGFloat = 10
  }
  
  let myConstant = MyConstant()
  </code></pre>
  
  <p>MainScreenVC    </p>
  
  <pre><code>override func viewWillAppear(_ animated: Bool) {
      myConstant.height = self.view.frame.size.height
  }
  
  func scrollViewDidScroll(_ scrollView: UIScrollView) {
      if (self.lastContentOffset &lt; scrollView.contentOffset.y) {
          NotificationCenter.default.post(name: Notifications.decreaseHeightNotification.name, object: nil)
          self.topViewConstraint.constant = -self.view.frame.height / 6
          UIView.animate(withDuration: 0.3, animations: {
              self.view.layoutIfNeeded()
          })
      } else if (self.lastContentOffset &gt; scrollView.contentOffset.y) {
          NotificationCenter.default.post(name: Notifications.increaseHeightNotification.name, object: nil)
          self.topViewConstraint.constant = 0
          UIView.animate(withDuration: 0.3, animations: {
              self.view.layoutIfNeeded()
          })
      }
      self.lastContentOffset = scrollView.contentOffset.y
  }
  </code></pre>
  
  <p>Cell.Swift</p>
  
  <pre><code>override func awakeFromNib() {
      super.awakeFromNib()
  
      NotificationCenter.default.addObserver(self, selector: #selector(decreaseHeight), name: Notification.Name("decreaseHeightNotification"), object: nil)
      NotificationCenter.default.addObserver(self, selector: #selector(increaseHeight), name: Notification.Name("increaseHeightNotification"), object: nil)
  
      self.contentView.translatesAutoresizingMaskIntoConstraints = false
      heightConstraint.constant = (myConstant.height / 3) - 10
      widthConstraint.constant = heightConstraint.constant * 1.5
  }
  
  @objc func decreaseHeight() {
      heightConstraint.constant = (myConstant.height / 6) - 10
      widthConstraint.constant = (heightConstraint.constant * 1.5)
      self.layoutIfNeeded()
  }
  
  @objc func increaseHeight() {
      heightConstraint.constant = (myConstant.height / 3) - 10
      widthConstraint.constant = (heightConstraint.constant * 1.5)
      self.layoutIfNeeded()
  }
  </code></pre>
  
  <p>Now when I scroll both simultaneously, the screen freezes. Also is there a better way of resizing the collectionViewCell size? </p>