在项目开发中经常遇到navigationBar把界面遮挡的情况。
其实只需要在controller的初始化方法或者viewdidload中加入下面这句
viewController.edgesForExtendedLayout = UIRectEdgeNone;
网上也有朋友说还需要加入以下三句
viewController.extendedLayoutIncludesOpaqueBars =NO;
viewController.modalPresentationCapturesStatusBarAppearance =NO;
viewController.navigationController.navigationBar.translucent =NO;
根据document的描述:
edgesForExtendedLayout
Discussion
This property is only applied to view controllers that are embedded in containers, such as UINavigationController or UITabBarController. View controllers set as the root view controller do not react to this property. Default value is UIRectEdgeAll.
可以看出这个属性就是用来处理view嵌入容器时的操作,关键是默认值是UIRectEdgeAll,导致在嵌入到容器中时会直接延生出去,从而造成界面被容器遮挡。
至于另外三句话都是用来告诉OS容器信息的。