今天,迫不及待把升級(jí)到Xcode12 和手機(jī)系統(tǒng)更新到iOS14 ,結(jié)果跑了項(xiàng)目是偷,發(fā)現(xiàn)在我的UITableView 列表中星压,一個(gè)UITableViewHeaderFooterView 背景設(shè)置為通明之后蒋伦,有一個(gè)毛玻璃顏色沃斤。
情景: 頁(yè)面是有一個(gè)backView 和 UITableView 組成圣蝎,backView放在底部,是有CAGradientLayer 畫了一個(gè)半圓衡瓶,而UITableView 的HeaderView 需要設(shè)置通明色徘公,來(lái)顯示背景半圓效果。如圖:
然而鞍陨,升級(jí)到iOS14之后成了這樣子
然后使用debug view hierarchy 看出來(lái)HeaderView 層級(jí)有所變化步淹,
old : ProbabilityCollegeHeaderView -> _UISystemBackgroundView -> _UITableViewHeaderFooterContentView
new : ProbabilityCollegeHeaderView -> _UISystemBackgroundView -> UIView -> _UITableViewHeaderFooterContentView
在系統(tǒng)View 嵌套里面多了一個(gè)UIView,并且Api方法里面沒(méi)有找到這個(gè)屬性
@available(iOS 6.0, *)
open class UITableViewHeaderFooterView : UIView {
public init(reuseIdentifier: String?)
public init?(coder: NSCoder)
/// Requests the view update its configuration for its current state. This method is called automatically
/// when the view's `configurationState` may have changed, as well as in other circumstances where an
/// update may be required. Multiple requests may be coalesced into a single update at the appropriate time.
@available(iOS 14.0, *)
open func setNeedsUpdateConfiguration()
/// When YES, the header/footer will automatically call -updatedConfigurationForState: on its `contentConfiguration` when the header/footer's
/// configuration state changes, and apply the updated configuration back to the header/footer. The default value is YES.
@available(iOS 14.0, *)
open var automaticallyUpdatesContentConfiguration: Bool
open var contentView: UIView { get }
// These properties will always return nil when a non-nil `contentConfiguration` is set.
@available(iOS, introduced: 6.0, deprecated: 100000, message: "Use UIListContentConfiguration instead, this property will be deprecated in a future release.")
open var textLabel: UILabel? { get }
@available(iOS, introduced: 6.0, deprecated: 100000, message: "Use UIListContentConfiguration instead, this property will be deprecated in a future release.")
open var detailTextLabel: UILabel? { get } // only supported for headers in grouped style
/// When YES, the header/footer will automatically call -updatedConfigurationForState: on its `backgroundConfiguration` when the header/footer's
/// configuration state changes, and apply the updated configuration back to the header/footer. The default value is YES.
@available(iOS 14.0, *)
open var automaticallyUpdatesBackgroundConfiguration: Bool
// This property is always nil when a non-nil `backgroundConfiguration` is set.
open var backgroundView: UIView?
open var reuseIdentifier: String? { get }
open func prepareForReuse() // if the view is reusable (has a reuse identifier), this is called just before the view is returned from the table view method dequeueReusableHeaderFooterViewWithIdentifier:. If you override, you MUST call super.
}
卻發(fā)現(xiàn)iOS14增加了backgroundConfiguration 配置方法诚撵。
backgroundConfiguration: 背景配置為您提供了一種輕巧的方式來(lái)為視圖創(chuàng)建背景。 使用背景配置键闺,可以獲得各種不同視圖狀態(tài)的系統(tǒng)默認(rèn)背景樣式寿烟。 您可以將后臺(tái)配置直接應(yīng)用于UICollectionView和UITableView中的單元格,頭部View和 底部View辛燥。
所以把UITableViewHeaderFooterView 中的backgroundConfiguration 設(shè)置為通明配置筛武,沒(méi)有默認(rèn)樣式就行了。
if #available(iOS 14.0, *) {
self.backgroundConfiguration = UIBackgroundConfiguration.clear()
} else {
// Fallback on earlier versions
}