Resolve IOS7 View controller's view overall up to 20 pixels
When we create a new project using XCODE5, we find that the overall view of the app that was running on the iOS6 was moved up by 20 pixels, because IOS 7 took the entire screen height (including the status bar and navigation bar) as the effective height of the view controller, The controller view on the iOS6 is then overlapped with the status bar above.
On this issue, our workaround:
When Apple upgraded to iOS7, the controller view was taken into account as a whole, so a new property Edgesforextendedlayoutwas added to the view controller in the IOS7 SDK, set this property to Uirectedgenone, and then all of the Viewcontroller view moves up to 20 pixels in total.
For our app to be able to support both iOS6 and iOS7, for convenience, we can build a baseviewcontroller, rewrite its Viewdidload method, the code is as follows
- (void) viewdidload{[Super Viewdidload];#if__iphone_os_version_max_allowed >= 70000if([Self respondstoselector: @selector (edgesforextendedlayout)]) {Self.edgesforextendedlayout=Uiextendededgenone; }#else floatBarheight =0; if(!isipad () &&![[UIApplication sharedapplication] Isstatusbarhidden]) {Barheight+=([[[UIApplication Sharedapplication]statusbarframe]). Size.Height; } if(Self.navigationcontroller &&!self.navigationcontroller.navigationbarhidden) {barheight+=Self.navigationController.navigationBar.frame.size.height; } for(UIView *viewinchself.view.subviews) {if([View Iskindofclass:[uiscrollviewclass]]) {View.frame= CGRectMake (view.frame.origin.x, View.frame.origin.y +barheight, View.frame.size.width, View.frame.size.height-barheight); } Else{view.frame= CGRectMake (view.frame.origin.x, VIEW.FRAME.ORIGIN.Y +barheight, View.frame.size.width, view.frame.size.height); } }#endif}
Use the macro __iphone_os_version_max_allowed to determine if the current version is iOS7 and above. >7.0 uses the new edgesforextendedlayout API to traverse the sub-view subviews down one by one and automatically calculates the offset to move based on the visual state of the status bar/navigation bar.
Note: If you have upgraded to XCODE5, setting the Top Bar of the navigation controller to a "Opacque ..." (opaque) type resolves this issue.
The official has given the status bar a solution that is compatible with both IOS6 and iOS7. Integrated in Xcode5, as shown in: Deltas meaning you can understand as incremental. Relative increments, fill in 20.