2017-10-14 29 views
5

我創建了單個視圖項目並添加了一個collectionView。我註冊UICollectionReusableViewiOS11 UICollectionSectionHeader剪裁滾動指標

final class TestReusableView: UICollectionReusableView { 
    override init(frame: CGRect) { 
    super.init(frame: frame) 
    backgroundColor = UIColor.red 
    } 
    ... 
} 

集的數據源和委託的一個簡單的子類來自

extension ViewController: UICollectionViewDataSource { 
    func numberOfSections(in collectionView: UICollectionView) -> Int { 
    return 1 
    } 

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return 100 
    } 

    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 
    let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: kHeader, for: indexPath) 
    return headerView 
    } 

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) 
    cell.backgroundColor = UIColor.blue 
    return cell 
    } 
} 

extension ViewController: UICollectionViewDelegateFlowLayout { 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { 
    return CGSize(width: collectionView.bounds.width, height: 88) 
    } 
} 

結果是節頭似乎被定位在垂直滾動指示器的上方。但是,如果我針對10.3.1模擬器運行該應用程序,則行爲將按我的預期運行。

Red section header is on top of the scroll indicator

+0

我曾經也遇到過類似的問題與iOS 11.0,其中部分頭被定位高於一切的看法。一切正常,在10.3。 – Aks

+2

絕對看起來像iOS 11.0+問題。我也遇到了它。最近的雷達我可以找到這個:http://www.openradar.me/34308893 – isoiphone

回答

1

我不能嘗試一下,但你可以嘗試添加以下內容到viewDidLoad()

let flow = collectionView.collectionViewLayout as! UICollectionViewFlowLayout 
flow.sectionHeadersPinToVisibleBounds = true 
+0

這只是將節標題固定到collectionView的頂部。問題在於部分頭部正在剪裁垂直滾動指示器 – CoderNinja

0

良好,即使我遇到了同樣的問題,在我的應用程序,它被提名爲發行2周。我沒有時間去研究爲什麼這隻會在iOS 11中失敗。因此,我所做的快速工作是將footerView的用法替換爲footerView,因爲footerView沒有這個問題。

4

這個工作對我來說:

- (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { 
    if (SystemVersionGraterOrEqual(11)) { 
     if ([elementKind isEqualToString:UICollectionElementKindSectionHeader]) { 
      view.layer.zPosition = 0; 
    } 
} 

}

+0

好的結果,儘管整個問題看起來像是一個錯誤,因爲玩z的位置不是必需的。 –