//
// GA_ViperSortViewController.swift
// GA_Placer2.0Demo
//
// Created by houjianan on 2017/2/6.
// Copyright © 2017年 houjianan. All rights reserved.
//
import UIKit
let kHomeFindLiveFeedCell = "GA_HomeFindLiveFeedCell"
let kHomeSelectedMoreCell = "GA_HomeSelectedMoreCell"
class GA_ViperSortViewController: GA_ViperBaseViewController {
lazy var collectionView: UICollectionView = {
let c = UICollectionView(frame: CGRect(x: 0, y: kNavigationHeight, width: self.view.ga_w, height: self.view.ga_h - kNavigationHeight), collectionViewLayout: GA_HomeFindLiveFeedCellLayout())
c.register(UINib(nibName: kViperSortHeaderCell, bundle: nil), forCellWithReuseIdentifier: kViperSortHeaderCell)
c.register(UINib(nibName: kViperSortCell, bundle: nil), forCellWithReuseIdentifier: kViperSortCell)
c.delegate = self
c.dataSource = self
c.isPagingEnabled = false
c.showsVerticalScrollIndicator = false
c.showsHorizontalScrollIndicator = false
c.backgroundColor = UIColor.white
c.contentInset = UIEdgeInsetsMake(0, 0, 0, 0)
self.view.addSubview(c)
return c
}()
override func myViewDidAppear() {
super.myViewDidAppear()
}
override func viewDidLoad() {
super.viewDidLoad()
collectionView.ga_show()
}
}
extension GA_ViperSortViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 20
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.row == 0 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kViperSortHeaderCell, for: indexPath) as! GA_ViperSortHeaderCell
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kViperSortCell, for: indexPath) as! GA_ViperSortCell
cell.sortLabel.text = "12312"
return cell
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath.row)
if indexPath.row == 0 {
} else {
}
}
}
// MARK: GA_SplitScreenLayout
private class GA_HomeFindLiveFeedCellLayout: UICollectionViewFlowLayout {
var cellCount: Int = 0
fileprivate override func prepare() {
super.prepare()
cellCount = collectionView!.numberOfItems(inSection: 0)
print(cellCount)
let w: CGFloat = AppWidth
let spcae: CGFloat = 14
let h: CGFloat = w / 2 - spcae - spcae / 2
itemSize = CGSize(width: h, height: h)
sectionInset = UIEdgeInsetsMake(spcae, spcae, spcae / 2, spcae)
minimumLineSpacing = spcae
minimumInteritemSpacing = 10
}
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
if indexPath.row == 0 {
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
attributes.size = CGSize(width: collectionView!.ga_w, height: kViperSortHeaderHeight)
attributes.center = CGPoint(x: collectionView!.ga_w / 2, y: kViperSortHeaderHeight / 2)
attributes.alpha = 1
return attributes
} else {
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
let w: CGFloat = AppWidth
let space: CGFloat = 14
let h: CGFloat = w / 2 - space - space / 2
attributes.size = CGSize(width: h, height: h)
let x = (indexPath.row % 2 == 0) ? (space*2 + h*1.5) : space + h / 2
let y = CGFloat(indexPath.row - ((indexPath.row % 2 == 1) ? 0 : 1) - (indexPath.row - ((indexPath.row % 2 == 1) ? 0 : 1))/2) * (h + space)
attributes.center = CGPoint(x: x, y: y)
attributes.alpha = 1
return attributes
}
}
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var attributes = [UICollectionViewLayoutAttributes]()
for i in 0..<cellCount {
let indexPath = IndexPath(row: i, section: 0)
attributes.append(layoutAttributesForItem(at: indexPath)!)
}
return attributes
}
}
swift - collectionView布局
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1.设计思想 1.1 首先,这是个水平布局 ,只是相对于普通流水布局多了一个水平缩放功能的实现.1.2 通过视图可...
- 1.对于圆形布局的设置: 1.1 不同于流水布局,因为流水布局的界面 只有水平方向上的布置以及竖直方向上的布置两种...