一、translucent
/* New behavior on iOS 7. Default is YES. You may force an opaque background by setting the property to NO. If the navigation bar has a custom background image, the default is inferred from the alpha values of the image—YES if it has any pixel with alpha < 1.0 If you send setTranslucent:YES to a bar with an opaque custom background image it will apply a system opacity less than 1.0 to the image. If you send setTranslucent:NO to a bar with a translucent custom background image it will provide an opaque background for the image using the bar's barTintColor if defined, or black for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil. */@property(nonatomic,assign,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(3_0) UI_APPEARANCE_SELECTOR; // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
iOS 7之後這個屬性預設為YES;
1、屬性設定YES時:
(1)、如果添加的第一個子視圖為UIScrollView,UIScrollView的原點在(0,0),UIScrollView的子視圖的原點在(0,64)點開始。
(2)、如果添加第一個子視圖非UIScrollView,原點在(0,0)點開始。
2、屬性設定為NO時:
(1)、添加的子視圖的原點都在(0,64)點開始。 二、automaticallyAdjustsScrollViewInsets
@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets API_DEPRECATED("Use UIScrollView's contentInsetAdjustmentBehavior instead", ios(7.0,11.0),tvos(7.0,11.0)); // Defaults to YES
該屬性在iOS11以後不起作用了;在iOS7-iOS10之間,translucent屬性設定為NO時,該屬性沒有效果,在translucent屬性設定為YES的前提下:
1、automaticallyAdjustsScrollViewInsets設定為YES:
(1)、如果添加的第一個子視圖為UIScrollView,UIScrollView的原點在(0,0),UIScrollView的子視圖的原點在(0,64)點開始。
(2)、如果添加第一個子視圖非UIScrollView,原點在(0,0)點開始。
2、automaticallyAdjustsScrollViewInsets設定為NO:
(1)、添加的子視圖的原點都在(0,0)點開始。 三、edgesForExtendedLayout
@property(nonatomic,assign) UIRectEdge edgesForExtendedLayout NS_AVAILABLE_IOS(7_0); // Defaults to UIRectEdgeAll
該枚舉如下幾個值:
typedef NS_OPTIONS(NSUInteger, UIRectEdge) { UIRectEdgeNone = 0, UIRectEdgeTop = 1 << 0, UIRectEdgeLeft = 1 << 1, UIRectEdgeBottom = 1 << 2, UIRectEdgeRight = 1 << 3, UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight} NS_ENUM_AVAILABLE_IOS(7_0);
在translucent屬性設定為NO時,該屬性沒有效果。
在translucent屬性設定為YES前提下:
1、edgesForExtendedLayout設定設定為UIRectEdgeNone時;
(1)、添加的子視圖的原點都在(0,64)點開始。
2、edgesForExtendedLayout設定設定為UIRectEdgeAll時;
(1)、遵循其他屬性設定結果。 四、contentInsetAdjustmentBehavior
/* Configure the behavior of adjustedContentInset. Default is UIScrollViewContentInsetAdjustmentAutomatic. */@property(nonatomic) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior API_AVAILABLE(ios(11.0),tvos(11.0));
前面說了在iOS11上,automaticallyAdjustsScrollViewInsets已經不起作用了,替換的是該屬性,設定如下:
if (@available(iOS 11.0, *)) { self.tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;}else { self.automaticallyAdjustsScrollViewInsets = NO;}
iOS11上對滾動視圖加入了self-sizeing,預設如果不去實現viewForHeaderInSection就不會調用heightForHeaderInSection,
網上好多都是描述如何適配iOS11的tableView的頂部位移。但是我一直沒有試出來,按照網上描述該問題解決如下:
self.tableView.estimatedRowHeight = 0;self.tableView.estimatedSectionHeaderHeight = 0;self.tableView.estimatedSectionFooterHeight = 0;
若有朋友有tableView頂部空白的demo,請留言給我,謝謝。。。