ios - How to prevent top bar from impeding view -
i'm writing first ios app , have noticed top bar appears on application:
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
Post a Comment