iOS7以后的控制器,苹果默认是全屏布局,如果有NavigationBar或者tabBar,不会让出这段距离。
UIScrollView *headScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 50)];
[self.view addSubview:headScrollView];
headScrollView.backgroundColor = [UIColor redColor];
self.headScrollView = headScrollView;
headScrollView.contentSize = CGSizeMake(450, 0);
headScroll 的Frame设置为(0,0,375,50),这时会加载到NavigationBar下面,被遮盖。
如果想不自动全屏布局,只需要更改scrollView的父控制器的属性,
viewController.edgesForExtendedLayout = UIRectEdgeNone;
edgesForExtendedLayout属性意思为边界扩展布局设置,默认值是UIRectEdgeAll,意思为全屏幕适配,
而我们改为UIRectEdgeNone,就会空出NavigationBar和tabBar的距离。