UIScreenのboundsとapplicationFrameの違い
StatusBarの有無で画面の使い方が微妙に変わり、毎回よく分からなくなるのでメモ。
NSLog(@"bounds = %@",NSStringFromCGRect([UIScreen mainScreen].bounds)); NSLog(@"applicationFrame = %@", NSStringFromCGRect([UIScreen mainScreen].applicationFrame));
出力がこちら
bounds = {{0, 0}, {320, 480}} applicationFrame = {{0, 20}, {320, 460}}
boundsは画面そのもののRectを、applicationFrameはStatusBarを取り除いた画面のRectを返す。
StatusBar | 基準 | 原点 | 原点(boundsから見た時) |
---|---|---|---|
あり | applicationFrame | {0, 0} | {0, 20} |
なし | bounds | {0,0} | {0, 0} |
StatusBarを表示しておくと、そのすぐしたが、yの原点になる。
なので、画面上から20の位置がyの基準0となる。