ios - How to prevent top bar from impeding view -


i'm writing first ios app , have noticed top bar appears on application:

enter image description here

my main window created this:

_window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; 

i noticed this similar question, not have navigation controller. root controller tab controller.

how can fix this?

you should use applicationframe instead of bounds. bounds return size including status bar while applicationframe return frame of content app.

_window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] applicationframe]]; 

in ios7 status bar can translucent. means applicationframe , bounds return same frame because content can drawn bellow status bar. fix can offset window bellow status bar (20px)

_window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] applicationframe]]; _window.clipstobounds = yes; _window.frame =  cgrectmake(0, 20, _window.frame.size.width, _window.frame.size.height - 20); _window.bounds = cgrectmake(0, 20, _window.frame.size.width, _window.frame.size.height); 

to make work on versions, add system version condition, this:

_window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] applicationframe]]; if ([[[uidevice currentdevice] systemversion] floatvalue] >= 7) {     _window.clipstobounds = yes;     _window.frame =  cgrectmake(0, 20, _window.frame.size.width, _window.frame.size.height - 20);     _window.bounds = cgrectmake(0, 20, _window.frame.size.width, _window.frame.size.height); } 

it's still better avoid modifying window frame, use applicationframe , offset content view 20px top on ios7 translucent status bar.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -