Presumably we have encountered a situation, obviously y coordinates set is 0, but is always annoying navigation bar to cover. For example, the following situation:
Yesterday, the program encountered a small situation, obviously y coordinates set is 0, but was blocked by the navigation bar. For example, the following situation:
Create test label
UILabel *testLabel = [[UILabel alloc] init]; testLabel.frame = CGRectMake (25, 0, self.view.bounds.size.width - 50, testLabel.text = 86); @ "test, you don't stop me"; testLabel.textAlignment = NSTextAlignmentCenter; testLabel.backgroundColor = [UIColor = blueColor]; testLabel.textColor [UIColor orangeColor]; [self.view addSubview:testLabel];
Is it very unfriendly? Fortunately, after iOS7, UIViewController introduced a new property: edgesForExtendedLayout. The default value for this property is UIRectEdgeAll. When your container is UINavigationController, the default layout starts at the top of the status bar, so it is blocked by the navigation bar.
@property (nonatomic, assign) UIRectEdge edgesForExtendedLayout NS_AVAILABLE_IOS (7_0); / / Defaults to UIRectEdgeAll
Problems will be solved! There are two methods:
method: modify edgesForExtendedLayout
Self.edgesForExtendedLayout = UIRectEdgeNone;
Set the edgesForExtendedLayout property to UIRectEdgeNone, so that the layout starts below the navigation bar. After setting, look at the effect:
Method two: navigation bar semi transparent property set to NO
@property (nonatomic, assign, getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS (3_0) UI_APPEARANCE_SELECTOR is NO on; / / Default iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
Before iOS 6 (including iOS 6) translucent default is NO, after iOS 7 default is YES.
Self.navigationController.navigationBar.translucent = NO;
After the package transparent property of the navigation bar is set to NO, the control can also be rendered perfectly. The result is the same as above.