1

When I print tableView.bounds in

ViewDidLoad and ViewWillAppear, it is (0.0, 0.0, 375.0, 667.0)

but in ViewDidAppear and scrollViewDidScroll methods, it is (0.0, -64.0, 375.0, 667.0)

Why the "Y" value in negative. and it keep on reducing negative value when I scroll down. As per my assumptions, it should increase in positive axis when scrolled down and when scroll up, the view goes origin goes up, so it should reduce in negative axis while scrolling up. That means, it is happening in opposite direction to my assumptions. Why is it like that?

Could someone explain this ?

Sai Jithendra
  • 439
  • 5
  • 16

1 Answers1

2

64 is the height of navigation bar and status bar. Also in viewDidLoad and viewWillAppear, bounds are not done laying out. You should get correct bounds in viewDidLayoutSubviews.

As for why y axis goes negative when scrolling down, that's because you're printing the bounds. If you want the value that you're expecting as mentioned in the question, you need to use tableView.contentOffset.y. I think this SO question regarding difference between frame and bounds will be helpful too.

Community
  • 1
  • 1
SFF
  • 877
  • 2
  • 11
  • 26