moonvader
moonvader

Reputation: 21121

Pause TableView scrolling

I have ViewController that have a UIView view and a TableView table inside it. View has big height so i want to hide it when user starts to scroll table - so table is now taking the whole screen. To do that I use this method.

func scrollViewWillBeginDragging(scrollView: UIScrollView) {
        //hide view or decrease it height
    }

I hide view with animation - so it takes few moments to hide. The problem is - when user start to scroll table and view is begin to become smaller - some of top cells of table are already not showing because they are in top.

enter image description here enter image description here

I want to pause scrolling - so that it can begin only after the view height is decreased. Also - I am afraid that it can be strange for users.

Upvotes: 0

Views: 128

Answers (2)

Burhanuddin Sunelwala
Burhanuddin Sunelwala

Reputation: 5343

What you can do is, you can give your tableView the entire screen and make another view with whatever height you want and make it as a header view of your tableView. So now the view will scroll as your tableView scrolls. Is this what you are looking for?

[tableView setHeaderView:<your-custom-header-view>];

Upvotes: 1

Shubhank
Shubhank

Reputation: 21805

You need to make the height change as per user scroll to make it efficient.

override another delegate function

func scrollViewDidScroll(_ scrollView: UIScrollView) {
   myView.heightConstraint = myView.originalHeight - scrollView.contentOffset.y;
}

The contentOffset property gives you the current amount of x,y scrolled in the scrollview from the origin.

Upvotes: 2

Related Questions