{"id":548,"date":"2016-06-16T14:50:33","date_gmt":"2016-06-16T05:50:33","guid":{"rendered":"http:\/\/www.nukoneko.info\/blog\/?p=548"},"modified":"2016-06-16T14:51:23","modified_gmt":"2016-06-16T05:51:23","slug":"chtcollectionviewwaterfalllayout-%e3%81%a7%e3%82%bb%e3%83%ab%e3%81%ae%e6%a8%aa%e5%b9%85%e5%8f%96%e5%be%97","status":"publish","type":"post","link":"https:\/\/www.nukoneko.info\/blog\/?p=548","title":{"rendered":"CHTCollectionViewWaterfallLayout \u3067\u30bb\u30eb\u306e\u6a2a\u5e45\u53d6\u5f97"},"content":{"rendered":"<p>Pinterest\u98a8\u306eCollectionView\u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<br \/>\n<a href=\"https:\/\/github.com\/chiahsien\/CHTCollectionViewWaterfallLayout\">CHTCollectionViewWaterfallLayout<\/a><br \/>\n\u3067\u3001\u30bb\u30eb\u306e\u6a2a\u5e45\u3092\u53d6\u308a\u305f\u304b\u3063\u305f\u306e\u3067\u30e1\u30e2<\/p>\n<h2>UICollectionViewLayout \u3092\u62e1\u5f35\u3057\u3066\u5b9f\u88c5<\/h2>\n<pre class=\"brush: swift; title: ; notranslate\" title=\"\">\nimport Foundation\nimport CHTCollectionViewWaterfallLayout\n\nextension UICollectionViewLayout {\n    func getCHTItemWidth() -&amp;gt; CGFloat{\n        guard let collectionViewRect = self.collectionView?.bounds else {\n            return 0\n        }\n        if self is CHTCollectionViewWaterfallLayout {\n            let me = self as! CHTCollectionViewWaterfallLayout\n            let columnWidth = collectionViewRect.width - (me.sectionInset.left + me.sectionInset.right)\n            return ( columnWidth - CGFloat(me.columnCount - 1) * me.minimumColumnSpacing ) \/ me.columnCount\n        } else {\n            return collectionViewRect.width\n        }\n    }\n}\n<\/pre>\n<h2>\u4f7f\u7528\u65b9\u6cd5<\/h2>\n<p>\u6a2a\u5e45:\u30bb\u30eb\u306e\u6a2a\u5e45 \u7e26\u5e45:\u30bb\u30eb\u306e\u6a2a\u5e45+60 \u306e\u30bb\u30eb\u3092\u8fd4\u3057\u305f\u3044\u6642<\/p>\n<pre class=\"brush: swift; title: ; notranslate\" title=\"\">\nextension ViewController : CHTCollectionViewDelegateWaterfallLayout {\n    func collectionView(collectionView: UICollectionView!,\n                        layout collectionViewLayout: UICollectionViewLayout!,\n                               sizeForItemAtIndexPath indexPath: NSIndexPath!) -&amp;gt; CGSize {\n        let w = collectionViewLayout.getCHTItemWidth()\n        return CGSize(width: w, height: w + 60)\n    }\n}\n<\/pre>\n<p>\u30bb\u30eb\u306e\u6a2a\u5e45\u306b\u5408\u308f\u305b\u305f\u67d4\u8edf\u306a\u30ec\u30a4\u30a2\u30a6\u30c8\u304c\u7d44\u3081\u3066\u697d\u3057\u3044\u3067\u3059<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pinterest\u98a8\u306eCollectionView\u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b CHTCollectionViewWaterfallLayout \u3067\u3001\u30bb\u30eb\u306e\u6a2a\u5e45\u3092\u53d6\u308a\u305f\u304b\u3063\u305f\u306e\u3067\u30e1\u30e2 UICollectionViewLayou [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,34],"tags":[],"class_list":["post-548","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift"],"_links":{"self":[{"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=548"}],"version-history":[{"count":1,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/548\/revisions"}],"predecessor-version":[{"id":549,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/548\/revisions\/549"}],"wp:attachment":[{"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}