Tuesday, January 21, 2014

Views getting hidden behind Navigation bar iOS7

In iOS7,
- View Controllers use full-screen layout.
- Status bar is transparent.
- Navigation bar is translucent(semi transparent) by default, 

and one major problem from these updates developers will face is,
When you run your existing app which is compatible for iOS 7 and below (say minimum deployment target is iOS6.0) then when you run your app in the new Xcode 5.x with iOS7 simulator (either 3.5 or 4 inch) a part or complete subviews of your viewController will go behind navigation bar.

Solution:
Use the below iOS 7 (Xcode5.x) compatible code snippet inside viewDidLoad method of your viewController 

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

As an example below is the graphical representation of this Problem,
1) Before Fix,
In the below image you can see the bordered subview's top portion is getting hidden by navigation bar


2) After fix,
Subview alignment became proper after fix see it in below image, 

A note on edgesForExtendedLayout:
edgesForExtendedLayout is to specify which edges of a view should be extended, regardless of bar translucency. By default, the value of this property is UIRectEdgeAll.

For further information on this topic you can visit Apple's developer document in the following URL,

2 comments:

  1. hey i have been searching high and low and your solution works. tks a million mate. cheers

    ReplyDelete