iOS开发-automaticallyAdjustsScrollViewInsets属性

//定义宏,判断ios7
#define IOS7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0
 
//添加代码
if  (IOS7)
{
     self .edgesForExtendedLayout = UIRectEdgeNone;                //视图控制器,四条边不指定
     self .extendedLayoutIncludesOpaqueBars =  NO ;                  //不透明的操作栏
    self.modalPresentationCapturesStatusBarAppearance = NO;

}


#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
     if  (IOS7)
     {
         self .edgesForExtendedLayout = UIRectEdgeNone;
         self .extendedLayoutIncludesOpaqueBars = NO ;
         self .modalPresentationCapturesStatusBarAppearance = NO ;
//        self.automaticallyAdjustsScrollViewInsets = NO;
//        self.navigationController.navigationBar.translucent = NO;
//        self.tabBarController.tabBar.translucent = NO;
     }
#endif


self.automaticallyAdjustsScrollViewInsets = NO;


看这个UIViewController的这个属性你就明白了,此属性默认为YES,这样UIViewController下如果只有一个UIScollView或者其子类,那么会自动留出空白,

让scollview滚动经过各种bar下面时能隐约看到内容。

但是每个UIViewController只能有唯一一个UIScollView或者其子类,

如果超过一个,需要将此属性设置为NO,自己去控制留白以及坐标问题。


#########################################################################################


最近遇到一个问题是这样的,App一般自己都会有一个UINavigationController,

顶部TableView如果有tableHeaderView如果设置起始位置是(0,0),本来应该起始位置是在从屏幕的(0,0),但是开始位置居然是从导航栏下面开始的。



iOS开发-automaticallyAdjustsScrollViewInsets属性_第1张图片


iOS开发-automaticallyAdjustsScrollViewInsets属性_第2张图片


A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.
 
Declaration
SWIFT
var automaticallyAdjustsScrollViewInsets: Bool
OBJECTIVE-C
@property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsets
Discussion
The default value of this property is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.
 
Availability
Available in iOS 7.0 and later.
简单点说就是automaticallyAdjustsScrollViewInsets根据按所在界面的status bar,navigationbar,与tabbar的高度,
自动调整scrollview的 inset。 就是说automaticallyAdjustsScrollViewInsets的默认值是YES,会自动调整scrollView的位置。

解决方案,将automaticallyAdjustsScrollViewInsets设置为no,不让viewController调整,我们自己修改布局即可~




你可能感兴趣的:(IOS)