2017-01-17 18 views
7

Tôi đang cố gắng để đạt được Pinterest bố trí trong ứng dụng của tôiUICollectionView chiều cao di động (Pinterest layout)

và tôi sử dụng phương pháp đại biểu sau đây để đạt được điều đó và thiết lập chiều cao di động

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
    let boundingRect = CGRect(x: 0, y: 0, width: self.view.frame.size.width/2 - 20, height: CGFloat(MAXFLOAT)) 
    let data = articles[indexPath.row] 
    let rect = AVMakeRect(aspectRatio: (data.coverImage?.size)!, insideRect: boundingRect) 
    return CGSize(width: rect.width, height: rect.height + 120) // Added 120 for a description I will add later 
} 

Nhưng tôi nhận được kết quả sau:

Here

nền màu xám là nền của di động, bạn có thể nhìn thấy thứ tại mỗi ô có chiều cao riêng (như mong đợi) nhưng có thêm khoảng trắng mà tôi không biết cách loại bỏ.

Làm cách nào để khắc phục sự cố này?

+0

Không ai thử điều này? Tại sao không có câu trả lời? – adev

Trả lời

0

Bố cục UICollectionView của bạn không đúng. Xóa khoảng cách ô và khoảng cách cột khỏi bảng phân cảnh hoặc qua phương thức CollectionViewDelegateFlowLayout.

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { 
    return CGFloat()// Your Value 
} 

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { 
    return CGFloat()// Your Value 
    } 
Các vấn đề liên quan