12

Why do I see in some sample code from Apple (such as PhotoScroller) that I should do the following in loadView:

CGRect frame = [[UIScreen mainScreen] bounds]; 

instead of

CGRect frame = [[UIScreen mainScreen] applicationFrame]; 

Does it make a difference to get the main screen's frame?

jscs
  • 63,694
  • 13
  • 151
  • 195
Joo Park
  • 3,115
  • 4
  • 27
  • 31

2 Answers2

17

ApplicationFrame is the screen size minus the size of the status bar (if visible), bounds is the screen size regardless of status bar.

So applicationFrame would return CGRectMake(0,0,320,460) assuming your app has the status bar set to be visible, while bounds would return CGRectMake(0,0,320,480) under the same conditions. Those numbers are assuming iPhone/iPod Touch screen sizes.

UIScreen Class Reference

jamone
  • 17,253
  • 17
  • 63
  • 98
  • 8
    I might be mistaken, but doesn't applicationFrame return CGRectMake(0, 20, 320, 460)? Where 20 is the offset of the status bar... – Niels R. Dec 06 '11 at 13:51
  • 2
    You're not mistaken, Niels :). The y-offset will be reported as 20 with a status bar, not 0. – Nate May 08 '12 at 01:25
  • Hi @jamone, what if the Personal Hotspot is shown? It seems to be taking 20 points high (same as the status bar). Would applicationFrame return CGRectMake(0, 40, 320, 440) on 3.5 inches iPhone and CGRectMake(0, 40, 320, 528) on 4 inches one? – George Nov 11 '13 at 04:10
  • @congliu That's right. on an iPhone 5, ApplicationFrame is usually (x=0, y=20, w=320, h=548) but when the Personal Hotspot or In Call Status Bar is present, this becomes (x=0, y=40, w=320, h=528) – Wheelie Oct 17 '14 at 08:31
2

iOS 9 Update

When using the Split View feature on the iPad, applicationFrame returns the size of your app window. bounds always returns the size of the device.

Code
  • 6,041
  • 4
  • 35
  • 75