아래와 같이 UICollectionView
을 초기화 중이므로 다른 섹션에 다른 줄 간격을 지정해야합니다.UICollectionView 레이아웃 대리자 메서드가 호출되지 않았습니다
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
var baseCollectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
baseCollectionView.backgroundColor = UIColor.clearColor()
baseCollectionView.translatesAutoresizingMaskIntoConstraints = false
baseCollectionView.showsVerticalScrollIndicator = false
baseCollectionView.delegate = self
baseCollectionView.dataSource = self
그리고 다음과 같이 배치 방법을 정의
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat
{
switch section {
case 0:
return 10.0
case 1:
return 10.0
case 2 :
return 10.0
case 3:
return 10.0
case 4 :
return 0.0
case 5 :
return 0.0
case 6 :
return 0.0
case 7 :
return 0.0
default:
return 0.0
}
}
그리고,
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat
{
switch section {
case 0:
return 10.0
case 1:
return 10.0
case 2 :
return 10.0
case 3:
return 10.0
case 4 :
return 0.0
case 5 :
return 0.0
case 6 :
return 0.0
case 7 :
return 0.0
default:
return 0.0
}
}
그리고 다른 대표
도minimumInteritemSpacingForSectionAtIndex
를 호출하지만
minimumLineSpacingForSectionAt
대리자 메서드 호출 받고되지 않는 방법 이 문제를 해결하기 위해 어디서 잘못 되었습니까?
위임 프로토콜을 준수했습니다. 다른 모든 사람들을 위해
다음class MyViewController: UIViewController , UICollectionViewDelegateFlowLayout , UICollectionViewDelegate , UICollectionViewDataSource
가고,
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
switch section {
case 0:
return CGSizeMake(140.0,self.contentView.frame.size.height)
case 1:
return CGSizeMake(140.0,self.contentView.frame.size.height)
case 2 :
return CGSizeMake(140.0,self.contentView.frame.size.height)
case 3 :
return CGSizeMake(140.0,self.contentView.frame.size.height)
case 4:
return CGSizeMake(self.contentView.frame.size.width,self.contentView.frame.size.height)
case 5:
return CGSizeMake(self.contentView.frame.size.width/2.0,self.contentView.frame.size.height)
case 6:
return CGSizeMake(75.0, self.contentView.frame.size.height)
case 7:
return CGSizeMake(((self.contentView.frame.size.width - 40.0)/3.0), 150.0)
default:
return CGSizeZero
}
}
는, 실제로 내 서버에서 전송 디스플레이 디자인은 다양한 상수를 설정하는 데 사용하고있다.
그것은 믿기 어렵습니다 _live_ 코드 ... 구문 적으로 전혀 컴파일 할 수없는 것 같습니다. – holex
당신은 무엇을 느끼게합니까? 그리고 나는 내 전체 코드가 아니라 내 대답을 얻는 데 필요한 코드 부분 만 게시 할 것입니다! –
@AvinashSharma 마지막 코멘트는 전적으로 아무런 도움이되지 않으며 어떤 식 으로든 도움이되지 않습니다. 참고로, 같은 것을 반환하면 사례를 그룹화 할 수 있습니다. 그리고 패턴 매치도 할 수 있습니다.'case 0 ... 3 : return 10' ad'default : return 0' – Fogmeister