{"id":1300,"date":"2013-10-05T16:36:54","date_gmt":"2013-10-05T23:36:54","guid":{"rendered":"http:\/\/zsprawl.com\/iOS\/?p=1300"},"modified":"2013-10-05T16:39:33","modified_gmt":"2013-10-05T23:39:33","slug":"fixing-the-phonegap-status-bar-in-ios7","status":"publish","type":"post","link":"http:\/\/zsprawl.com\/iOS\/2013\/10\/fixing-the-phonegap-status-bar-in-ios7\/","title":{"rendered":"Fixing the PhoneGap Status Bar in iOS7"},"content":{"rendered":"<p>One of the most noticeable changes in iOS7 when developing an App with PhoneGap is the new Fullscreen &#8220;feature&#8221;. xcode and Phonegap don&#8217;t appear to respect any of the status bar settings, and you are stuck adjusting the CSS or editing the core PhoneGap files to compensate. Here is how my infamous <a href=\"http:\/\/zsprawl.com\/iOS\/zapps\/whipped\/\" target=\"_blank\">Whipped zApp<\/a> looks after the update to iOS7.<\/p>\n<p><a href=\"http:\/\/zsprawl.com\/iOS\/wp-content\/uploads\/2013\/10\/2013-10-05-16.20.04.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/zsprawl.com\/iOS\/wp-content\/uploads\/2013\/10\/2013-10-05-16.20.04-169x300.png\" alt=\"2013-10-05 16.20.04\" width=\"169\" height=\"300\" class=\"aligncenter size-medium wp-image-1301\" \/><\/a><\/p>\n<p>Notice the status bar issues at the top, as well as the humongous whipped images. Let&#8217;s tackle the Status Bar issue first since it most likely <a href=\"https:\/\/groups.google.com\/forum\/#!topic\/phonegap\/nNUgSOfpt5Q\" target=\"_blank\">plagues many PhoneGap developers right now<\/a>. There are numerous ways to fix this, but perhaps the most elegant if you are using PhoneGap 3.0 was suggested by <a href=\"http:\/\/shazronatadobe.wordpress.com\" target=\"_blank\">Shazron<\/a> from Adobe:<\/p>\n<p>[code]function onDeviceReady() {<br \/>\n    if (parseFloat(window.device.version) === 7.0) {<br \/>\n          document.body.style.marginTop = &#8220;20px&#8221;;<br \/>\n    }<br \/>\n}<\/p>\n<p>document.addEventListener(&#8216;deviceready&#8217;, onDeviceReady, false);[\/code]<\/p>\n<p>Unfortunately, this did not work for me, since I decided not to update all the way to PhoneGap 3.0 quite yet due to the lack of good documentation forthcoming from Adobe, and a number of bugs that have been introduced with the latest major revision. In my case, I was forced to edit the MainViewController.m file as follows:<\/p>\n<p>[code]- (void)viewWillAppear:(BOOL)animated<br \/>\n{<br \/>\n    \/\/ Set the main view to utilize the entire application frame space of the device.<br \/>\n    \/\/ Change this to suit your view&#8217;s UI footprint needs in your application.<\/p>\n<p>    UIView* rootView = [[[[UIApplication sharedApplication] keyWindow] rootViewController] view];<br \/>\n    CGRect webViewFrame = [[[rootView subviews] objectAtIndex:0] frame];  \/\/ first subview is the UIWebView<\/p>\n<p>    if (CGRectEqualToRect(webViewFrame, CGRectZero)) { \/\/ UIWebView is sized according to its parent, here it hasn&#8217;t been sized yet<br \/>\n        self.view.frame = [[UIScreen mainScreen] applicationFrame]; \/\/ size UIWebView&#8217;s parent according to application frame, which will in turn resize the UIWebView<br \/>\n    }<\/p>\n<p>    \/\/ Begin &#8211; New for iOS7<br \/>\n    NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@&#8221;.&#8221;];<br \/>\n    if ([[vComp objectAtIndex:0] intValue] >= 7) {<br \/>\n        CGRect oldBounds = [self.view bounds];<\/p>\n<p>        CGRect newViewBounds = CGRectMake(0, -20, oldBounds.size.width, oldBounds.size.height-20);<br \/>\n        CGRect newWebViewBounds = CGRectMake(0, 0, oldBounds.size.width, oldBounds.size.height-20);<\/p>\n<p>        [self.view setBounds:newViewBounds];<br \/>\n        [self.webView setBounds:newWebViewBounds];<br \/>\n    }<br \/>\n    \/\/ End &#8211; New for iOS 7<\/p>\n<p>    [super viewWillAppear:animated];<br \/>\n}[\/code]<\/p>\n<p>Both snippets of code seek to move the view window down 20 pixels to leave space for the Status Bar.<\/p>\n<p>Now all that is left is to fix my oversized images. This was simply done with some CSS. Originally the code was:<\/p>\n<p>[code]#buttons li a img {<br \/>\n  height: 90%;<br \/>\n}[\/code]<\/p>\n<p>The seems to work fine in everything pre-iOS7, but I had to add another CSS parameter to make it work in iOS7 as well.<\/p>\n<p>[code]#buttons li a img {<br \/>\n  height: 90%;<br \/>\n  max-height: 90%;<br \/>\n}[\/code]<\/p>\n<p>Not sure why it is needed honestly, but it doesn&#8217;t hurt backwards compatibility. Hope it helps someone else out!<\/p>\n<p><a href=\"http:\/\/zsprawl.com\/iOS\/wp-content\/uploads\/2013\/10\/2013-10-05-16.34.12.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/zsprawl.com\/iOS\/wp-content\/uploads\/2013\/10\/2013-10-05-16.34.12-169x300.png\" alt=\"2013-10-05 16.34.12\" width=\"169\" height=\"300\" class=\"aligncenter size-medium wp-image-1302\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most noticeable changes in iOS7 when developing an App with PhoneGap is the new Fullscreen &#8220;feature&#8221;. xcode and Phonegap don&#8217;t appear to respect any of the status bar settings, and you are stuck adjusting the CSS or editing the core PhoneGap files to compensate. Here is how my infamous Whipped zApp looks <a href=\"http:\/\/zsprawl.com\/iOS\/2013\/10\/fixing-the-phonegap-status-bar-in-ios7\/#more-'\" class=\"more-link\"><br \/>more \u00bb<\/a><\/p>\n","protected":false},"author":318,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,24,19,38,43,23],"tags":[121,36,14,5,88,34,87,119],"class_list":["post-1300","post","type-post","status-publish","format-standard","hentry","category-advertising","category-blog","category-camera","category-cordova","category-css","category-whipped","tag-cordova","tag-css3","tag-iad","tag-ios","tag-ios7","tag-phonegap","tag-status-bar","tag-whipped"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/1300"}],"collection":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/users\/318"}],"replies":[{"embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/comments?post=1300"}],"version-history":[{"count":3,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/1300\/revisions"}],"predecessor-version":[{"id":1305,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/1300\/revisions\/1305"}],"wp:attachment":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/media?parent=1300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/categories?post=1300"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/tags?post=1300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}