Kodowanie dla systemu iOS 8+.UICollectionView AutoSize wysokość nagłówka
Mam UICollectionReusableView
który jest używany jako nagłówka UICollectionView
class UserHeader: UICollectionReusableView {
...
}
moim zdaniem Kolekcja robi kilka rzeczy:
Ładunki NIB w viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
resultsCollectionView.registerNib(UINib(nibName: "UserHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "UserHeader")
}
Zestawy nagłówku wysokość w referenceSizeForHeaderInSection
.
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSizeMake(0, 500)
}
Jednak moja UserHeader
widok składa się z wielu UILabel, UIViews kto wysokość zmienia się w czasie wykonywania, w jaki sposób można określić wysokość dla referenceSizeForHeaderInSection
, który jest dynamiczny? Lub jeśli nie mam korzystać z automatycznej zmiany rozmiaru w iOS 8+ w wersji referenceSizeForHeaderInSection
, proszę o informację, co powinienem użyć. Z góry dziękuję.
Przez wzgląd na kompletność, oto jak załadować widok, ale nie jestem pewien, czy to jest istotne dla tej dyskusji:
func collectionView(collectionView: UICollectionView!, viewForSupplementaryElementOfKind kind: String!, atIndexPath indexPath: NSIndexPath!) -> UICollectionReusableView! {
var reusableview:UICollectionReusableView = UICollectionReusableView()
if (kind == UICollectionElementKindSectionHeader) {
let userHeaderView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "UserHeader", forIndexPath: indexPath) as! UserHeader
... extra code to modify UserHeader
reusableview = userHeaderView
}
return reusableview
}