1. 程式人生 > >ios中navigation controller的漂移問題

ios中navigation controller的漂移問題

   self.edgesForExtendedLayout = UIRectEdgeNone;//設定navgationcontrllor的漂移問題,和navgation的穿透問題在iOS 7中,蘋果引入了一個新的屬性,叫做[UIViewController setEdgesForExtendedLayout:],它的預設值為UIRectEdgeAll。當你的容器是navigation controller時,預設的佈局將從navigation bar的頂部開始。這就是為什麼所有的UI元素都往上漂移了44pt。有時會加上頂部tool bar的高度 20, 20+44 = 64

   CGRect viewBounds = self.view.bounds;

   float navBarHeight = self.navigationController.navigationBar.frame.size.height + 20;

   viewBounds.size.height = ([[UIScreen mainScreen] bounds].size.height) - navBarHeight;

  self.view.bounds = viewBounds;