iOS7 edgesForExtendedLayout

 When your container is a navigation controller, the default layout will start at the top of the navigation bar. That's why all UI elements drift up by 44pt. Add the following code to fix it - (void)viewDidLoad

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

 

 

I encountered a problem when I was doing UISearchBar and UISearchDisplayController today, and the position of the shadow part was deviated when I clicked the search bar.

As shown below:

I always thought it was very strange. I made a demo later, copied the same code and found that it was normal.

Then look at the code one by one and see the following:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    {
       self.edgesForExtendedLayout = UIRectEdgeNone;
    }
}

 

 

Find the suspicious, Google's iOS 7 tutorial: let the program support both iOS 6 and iOS 7 , find the answer.

 

reason:

 

In iOS  7, Apple introduced a new property called [UIViewController setEdgesForExtendedLayout:], whose default value is UIRectEdgeAll. When your container is a navigation controller, the default layout will start at the top of the navigation bar. That's why all UI elements drift up by 44pt.

A quick fix for this is - (void)viewDidLoadto add the following line of code to the method:

self.edgesForExtendedLayout = UIRectEdgeNone;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326489978&siteId=291194637
ios