2017-08-16 19 views
0

をスクロールする細胞を防ぐ私はUICollectionViewの表示/非スティッキーヘッダーの後ろ

flowLayout.sectionHeadersPinToVisibleBounds = true 

スティッキーヘッダを持つコレクションビューを持っている私の問題は、私のヘッダーの上半分が半透明であると私は私のセルを上にスクロールするとき、私が見ることができるということですヘッダーの後ろにあるセルのスクロール

ヘッダーの後ろのセルビューの部分を非表示にしたいとします。私のイメージでは、赤の後ろに緑色が見えないようにしています。残りの行動は、私が保持したいものです。私はこれを必要と

理由は私が

Sticky CollectionViewHeaders

@IBOutlet weak var collectionView: UICollectionView! 
override func viewDidLoad() { 
    super.viewDidLoad() 
    self.collectionView.alwaysBounceVertical = true 
    collectionView.register(UINib.init(nibName: EXAMPLE_CELL_REUSE_ID, bundle: nil), forCellWithReuseIdentifier: EXAMPLE_CELL_REUSE_ID) 
    collectionView.register(UINib.init(nibName: EXAMPLE_HEADER_REUSE_ID, bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: EXAMPLE_HEADER_REUSE_ID) 

    if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout { 
     flowLayout.headerReferenceSize = CGSize(width: 400, height: 100) 
     flowLayout.sectionHeadersPinToVisibleBounds = true 
    } 
} 




func numberOfSections(in collectionView: UICollectionView) -> Int { 
    return sections.count; 
} 

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return 1 //self.sections[section].1; 
} 



func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let exampleCell = collectionView.dequeueReusableCell(withReuseIdentifier: EXAMPLE_CELL_REUSE_ID, for: indexPath) as! MyCellCollectionViewCell; 

    exampleCell.headerLabel.text = "Cell" 
    exampleCell.backgroundColor = UIColor.green 

    return exampleCell; 
} 


func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 
    if kind == UICollectionElementKindSectionHeader { 
     if let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: EXAMPLE_HEADER_REUSE_ID, for: indexPath) as? ExampleHeader { 
     // header.backgroundColor = UIColor(red: 1.0, green: 0, blue: 0, alpha: 0.5) 
     return header 
     } else { 
     return UICollectionReusableView() 

     } 
    } 
    return UICollectionReusableView() 
} 

を示すする必要がある非常に奥に壁紙の画像を持っている私は、ここで問題が似ているかもしれないと思うが、何の応答はありませんそれが同じ問題であるかどうかは明らかではありません。 Transparent sticky header ui collectionview don't show cells underneath

+0

使用したコードを表示します。 – PGDev

+0

sectionHeadersPinToVisibleBoundsを除いて、コードは標準です。とにかく投稿しました –

答えて

0

私はあなたのように非常に簡単な設定を作成しており、正常に動作しています。

class ViewController: UIViewController, UICollectionViewDataSource 
{ 
    @IBOutlet weak var collectionView: UICollectionView! 

    override func viewDidLoad() 
    { 
     super.viewDidLoad() 
     self.collectionView.alwaysBounceVertical = true 

     if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout 
     { 
      flowLayout.headerReferenceSize = CGSize(width: 400, height: 100) 
      flowLayout.sectionHeadersPinToVisibleBounds = true 
     } 
    } 

    func numberOfSections(in collectionView: UICollectionView) -> Int 
    { 
     return 10 
    } 

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

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

    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView 
    { 
     if kind == UICollectionElementKindSectionHeader 
     { 
      return collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "rview", for: indexPath) 
     } 
     return UICollectionReusableView() 
    } 
} 
+0

何がうまくいくのですか?私のコレクションのビューが動作し、私の質問は、透明なヘッダーを持つ方法、それの背後にあるセルを見ることなくです。 –

+0

ヘッダーをどのように透明にしましたか?私はそれを行うコードを意味する – PGDev

+0

ああ..本当に申し訳ありません。あなたの質問を完全に理解していない。このリンクhttps://stackoverflow.com/questions/33010199/make-transparent-stickyheader-like-weather-iosが役立つかもしれません。 – PGDev

関連する問題