0

As the title explains, I'm creating a UIScrollView programmatically in my view controller's loadView, which I will then set to self.view.

_pagingScrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = _pagingScrollView;

If I inspect _pagingScrollView.frame at the end of loadView, it's equal to

{{0,0}, {320,480}}.

However, if I inspect the same property within my scrollViewDidScroll delegate, it switches to

{{0,0},{320,367}}

How do I alloc/init my scrollView so that it's height takes the tab/nav bars into account from the beginning, and gives me 367? I know I could simply hard code 367, but I'd like to know what's going on here and why it starts out with one value and then changes.

djibouti33
  • 12,102
  • 9
  • 83
  • 116

2 Answers2

1

Why not create the UIScrollView with known bounds

_pagingScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,387];

or subtract the height of TabBar or NavBar from UIScreen bounds

atastrophic
  • 3,153
  • 3
  • 31
  • 50
0

I believe the problem you're seeing is caused by your use of [UIScreen mainscreen] which refers to the whole window (320,480) and doesn't care about the Nav/Tab views inside of it.

Rather than using that, you may instead desire to use the applicationFrame method.

See this related post -- How to get the actual [UIScreen mainScreen] frame size?

Additionally, if your vc's superView/superViewController are set, you could use those to get more relevant size information, because the MainScreen will still only refer to the whole window, and not take sub view controllers, like nav/tabs into account.

Community
  • 1
  • 1
shortstuffsushi
  • 2,271
  • 19
  • 33