{"id":280,"date":"2015-08-30T23:18:48","date_gmt":"2015-08-30T15:18:48","guid":{"rendered":"http:\/\/www.olinone.com\/?p=280"},"modified":"2019-10-29T20:50:35","modified_gmt":"2019-10-29T12:50:35","slug":"uicollectionview%e9%ab%98%e7%ba%a7%e8%bf%9b%e9%98%b6%e7%af%87","status":"publish","type":"post","link":"http:\/\/www.olinone.com\/?p=280","title":{"rendered":"UICollectionView\u9ad8\u7ea7\u8fdb\u9636\u7bc7"},"content":{"rendered":"<p><em>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904:<a href=\"http:\/\/www.olinone.com\/\">http:\/\/www.olinone.com\/<\/a><\/em><\/p>\n<p>HI\uff0c\u4eb2\u7231\u8bfb\u8005\u670b\u53cb\u4eec\uff0c\u53c8\u5230\u4e86\u535a\u5ba2\u66f4\u65b0\u7684\u65f6\u95f4\uff0c\u5728\u7ecf\u5386\u4e86\u5927\u534a\u5e74\u7684\u6c89\u6dc0\uff0c\u76ee\u524d\u535a\u5ba2\u65e5\u8bbf\u95ee\u4eba\u6b21\u5df2\u7a81\u7834400\u5927\u5173\uff0c\u6700\u9ad8\u5cf0\u8fbe\u52302600\u4eba\u6b21\uff0c\u975e\u5e38\u611f\u8c22\u5404\u4f4d\u670b\u53cb\u7684\u6765\u8bbf\uff0c\u5728\u4ee5\u540e\u7684\u535a\u5ba2\u4e2d\u4e89\u53d6\u4e3a\u5927\u5bb6\u5e26\u6765\u66f4\u591a\u7684\u5e72\u8d27\u3002\u5404\u4f4d\u670b\u53cb\u5982\u679c\u6709\u597d\u7684\u6587\u7ae0\u6216\u8005\u9898\u6750\u90fd\u53ef\u4ee5\u63a8\u8350\u7ed9\u6211\uff0c\u6709\u4ec0\u4e48\u60f3\u4e86\u89e3\u7684\u77e5\u8bc6\uff0c\u90fd\u53ef\u4ee5\u5728\u4e0b\u9762\u8ddf\u6211\u7559\u8a00\uff0c\u6216\u8005@<a href=\"http:\/\/weibo.com\/u\/5474633407\">\u5e9e\u6d77\u7901\u7684\u4e2a\u4eba\u7a7a\u95f4<\/a><\/p>\n<p>\u5728\u804a\u5b8c\u51e0\u6b21\u7406\u8bba\u540e\uff0c\u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u5173\u4e8eUI\u7684\u6587\u7ae0\uff0c\u770b\u6807\u9898\u5927\u5bb6\u5df2\u7ecf\u77e5\u9053\u4e86\uff0c\u6ca1\u9519\uff0c\u5c31\u662f\u5927\u5bb6\u6240\u719f\u6089\u7684UICollectionView\u3002\u8bf4\u8d77github\u4e0a\u8d6b\u8d6b\u6709\u540d\u7684\u5361\u7247\u5c55\u793a\u89c6\u56fe<a href=\"https:\/\/github.com\/nicklockwood\/iCarousel\">iCarousel<\/a>\uff0c\u5927\u591a\u6570iOS\u5f00\u53d1\u4eba\u5458\u6216\u591a\u6216\u5c11\u90fd\u6709\u542c\u8fc7\u6216\u4f7f\u7528\u8fc7\uff0c\u5176\u4e30\u5bcc\u7684\u5c55\u793a\u6837\u5f0f\u7ecf\u5e38\u51fa\u73b0\u5728\u67d0\u4e9bAPP\u7684\u4e00\u7ea7\u8def\u5f84\uff0c\u5176\u5b9e\uff0c\u82f9\u679c\u516c\u53f8\u9488\u5bf9\u5361\u7247\u6837\u5f0f\u796d\u51fa\u4e86\u81ea\u5df1\u7684\u89e3\u51b3\u65b9\u6848\u2014\u2014UICollectionView<\/p>\n<p>\u5e9f\u8bdd\u5c11\u8bf4\uff0c\u5148\u4e0a\u5e72\u8d27<a href=\"https:\/\/github.com\/panghaijiao\/HJCarouselDemo\">HJCarouselDemo<\/a><\/p>\n<p><a href=\"http:\/\/cdn.olinone.com\/HJCarousel.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/camo.githubusercontent.com\/dcffc80dc4d4eb4aa3a74e9341706573f2266d71\/687474703a2f2f3770756d376f2e636f6d312e7a302e676c622e636c6f7564646e2e636f6d2f484a4361726f7573656c2e676966\" alt=\"\" width=\"268\" height=\"480\" \/><\/a><\/p>\n<p>\u770b\u5b8cGIF\u5c55\u793a\u7684\u6548\u679c\uff0c\u5404\u4f4d\u662f\u5426\u5df2\u7ecf\u8822\u8822\u6b32\u52a8\uff0c\u8fd9\u4e0d\u5c31\u662f<a href=\"https:\/\/github.com\/nicklockwood\/iCarousel\">iCarousel<\/a>\u89c6\u56fe\u561b\uff0c\u6ca1\u9519\uff01\u4f46\u662f\u4eca\u5929\u6211\u4eec\u91c7\u7528UICollectionView\u5b9e\u73b0\u8fd9\u4e9b\u6548\u679c\u3002\u5e73\u5e38\u5f00\u53d1\u4e2d\uff0c\u6700\u719f\u6089\u7684\u83ab\u8fc7\u4e8eUICollectionViewFlowLayout\uff0c\u5176\u5b9eUICollectionViewFlowLayout\u76f8\u5f53\u4e8e\u82f9\u679c\u63d0\u524d\u5b9a\u4e49\u7684\u4e00\u4e2a\u7279\u6b8aUICollectionViewLayout\u3002<\/p>\n<p>\u5148\u770b\u770bUICollectionViewLayout\u7c7b\u7684\u5b98\u65b9\u6587\u6863\uff08\u597d\u5427\uff0c\u539f\u8c05\u6211\u534a\u5929\u6253\u4e0d\u5f00\u82f9\u679c\u7f51\u5740\uff0c\u6700\u8fd1\u654f\u611f\u671f\uff0c\u5404\u79cd\u548c\u8c10)\uff0c\u8fd8\u662f\u76f4\u63a5\u770b\u4ee3\u7801\u5427\uff0c\u603b\u4e4b\uff0c\u81ea\u5b9a\u4e49UICollectionViewLayout\uff0c\u5fc5\u987b\u5b9e\u73b0\u4ee5\u4e0b\u51e0\u4e2a\u51fd\u6570<\/p>\n<ul class=\"ul1\">\n<li class=\"li1\"><span class=\"s2\">collectionViewContentSize<\/span><\/li>\n<li class=\"li1\"><span class=\"s2\">layoutAttributesForElementsInRect:<\/span><\/li>\n<li class=\"li1\"><span class=\"s2\">layoutAttributesForItemAtIndexPath:<\/span><\/li>\n<li class=\"li1\"><span class=\"s2\">layoutAttributesForSupplementaryViewOfKind:atIndexPath:<\/span><span class=\"s3\"> (if your layout supports supplementary views) <\/span><\/li>\n<li class=\"li1\"><span class=\"s2\">layoutAttributesForDecorationViewOfKind:atIndexPath:<\/span><span class=\"s3\"> (if your layout supports decoration views) <\/span><\/li>\n<li class=\"li1\"><span class=\"s2\">shouldInvalidateLayoutForBoundsChange:<\/span><\/li>\n<\/ul>\n<p>\u770b\u51fd\u6570\u540d\u5c31\u53ef\u4ee5\u77e5\u9053\u5404\u4e2a\u51fd\u6570\u5b9e\u73b0\u7684\u529f\u80fd\uff1a\u7b2c\u4e00\u4e2a\u5b9a\u4f4dView\u7684contentSize\uff0c\u7b2c\u4e8c\u4e2a\u51fd\u6570\u5b9a\u4e49\u5c4f\u5e55\u5c55\u793a\u7684\u8303\u56f4\u548c\u6570\u91cf\uff0c\u7b2c\u4e09\u4e2a\u5b9a\u4e49cell\u7684\u5e03\u5c40\uff0c\u7b2c\u56db\u4e2a\u548c\u7b2c\u4e94\u4e2a\u662f\u53ef\u9009\u9879\uff0c\u5b9a\u4e49SupplementaryView\u4ee5\u53caDecorationView\u7684\u5e03\u5c40\uff0c\u6700\u540e\u4e00\u4e2a\u5b9a\u4e49\u662f\u5426\u91cd\u65b0\u5e03\u5c40<\/p>\n<p>UICollectionViewLayout\u7684\u7cbe\u9ad3\u5728\u4e8e\u4f60\u53ef\u4ee5\u5b9a\u4e49\u6bcf\u4e2acell\u7684UICollectionViewLayoutAttributes\u5c5e\u6027\uff0c\u5305\u62ec<\/p>\n<pre class=\"lang:objc highlight:0 decode:true \">@property (nonatomic) CGRect frame;\r\n@property (nonatomic) CGPoint center;\r\n@property (nonatomic) CGSize size;\r\n@property (nonatomic) CATransform3D transform3D;\r\n@property (nonatomic) CGRect bounds NS_AVAILABLE_IOS(7_0);\r\n@property (nonatomic) CGAffineTransform transform NS_AVAILABLE_IOS(7_0);\r\n@property (nonatomic) CGFloat alpha;\r\n@property (nonatomic) NSInteger zIndex; \/\/ default is 0<\/pre>\n<p>\u901a\u8fc7\u5b9a\u4e49transform3D\u5c5e\u6027\u53ef\u4ee5\u5b9e\u73b0\u89c6\u56fe\u7684\u65cb\u8f6c\u3001\u653e\u5927\u4ee5\u53ca\u900f\u89c6\u7b49\u6548\u679c\uff0c\u5177\u4f53\u5b9e\u73b0\u53c2\u8003<a href=\"https:\/\/github.com\/panghaijiao\/HJCarouselDemo\">HJCarouselDemo<\/a><\/p>\n<p>\u5728\u8fd9\u91cc\u683c\u5916\u9700\u8981\u5f3a\u8c03\u7684\u4e00\u70b9\uff0c\u90a3\u5c31\u662fpage\u5c5e\u6027\uff0c\u5f53\u6ed1\u52a8\u505c\u6b62\u65f6\uff0c\u5e0c\u671bUICollectionView\u6ed1\u52a8\u5230\u5361\u7247\u7684\u4e2d\u5fc3\uff0c\u800c\u4e0d\u662f\u4efb\u610f\u4f4d\u7f6e<\/p>\n<p>UICollectionViewLayout\u5b9a\u4e49\u51fd\u6570<\/p>\n<ul>\n<li class=\"p1\"><span class=\"s1\">&#8211; (<\/span><span class=\"s2\">CGPoint<\/span><span class=\"s1\">)targetContentOffsetForProposedContentOffset:(<\/span><span class=\"s2\">CGPoint<\/span><span class=\"s1\">)proposedContentOffset withScrollingVelocity:(<\/span><span class=\"s2\">CGPoint<\/span><span class=\"s1\">)velocity<\/span><\/li>\n<\/ul>\n<p class=\"p1\">\u5176\u4e2d \uff0cproposedContentOffset\u4e3a\u7cfb\u7edf\u671f\u671b\u6ed1\u52a8\u5230\u7684\u4f4d\u7f6e\uff0cvelocity\u4e3a\u52a0\u901f\u5ea6\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e24\u4e2a\u53c2\u6570\u4ee5\u53ca\u5f53\u524d\u6240\u5728\u7684\u4f4d\u7f6e\u8ba1\u7b97\u51fa\u4f60\u5e0c\u671b\u5b83\u6ed1\u52a8\u5230\u7684\u4f4d\u7f6e\uff0c\u5177\u4f53\u7b97\u6cd5\u6839\u636e\u9700\u6c42\u7684\u4e0d\u540c\u6765\u5b9e\u73b0<\/p>\n<p class=\"p1\">\u6709\u7528\u8fc7\u6211\u4eec\u5929\u5929\u52a8\u542ciOS\u5ba2\u6237\u7aef\u6216\u8005QQ\u97f3\u4e50\u7684\u670b\u53cb\uff0c\u53ef\u80fd\u90fd\u975e\u5e38\u719f\u6089\u8fd9\u4e2a\u52a8\u753b\u6548\u679c\uff0c\u5929\u5929\u52a8\u542c\u7684\u63a8\u8350\u9875\u9762\u4ee5\u53caQQ\u97f3\u4e50\u7684\u7535\u53f0\u754c\u9762\uff0c\u662f\u4e0d\u662f\u5c31\u8fd9\u6837\uff0c\u563f\u563f\uff01\u91cd\u8981\u7684\u4e8b\u8bf4\u4e09\u904d\uff0c\u8d76\u5feb\u4e0b\u8f7d\u5929\u5929\u52a8\u542c\u5ba2\u6237\u7aef\uff0c\u8ddf\u6211\u4eec\u4e00\u8d77\u6447\u6446\u8d77\u6765~~~<\/p>\n<h2 class=\"p1\">\u756a\u5916\u7bc7<\/h2>\n<p>\u8bf4\u5b8cView\uff0c\u63a5\u4e0b\u6765\u804a\u804aController\uff0c\u8c08\u4ec0\u4e48\u4e86\uff1f\u8c08\u8c08\u5b83\u4eec\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u6700\u8fd1\u4e1a\u754c\u5bf9\u8bbe\u8ba1\u6a21\u5f0f\u7684\u8bdd\u9898\u8ba8\u8bba\u6bd4\u8f83\u70ed\u70c8\uff0cMVC\u3001MVVM\u3001MVP\u7b49\u7b49\uff0c\u4e0d\u77e5\u9053\u5404\u4f4d\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u4e00\u822c\u4f7f\u7528\u4ec0\u4e48\u6837\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u6709\u4ec0\u4e48\u597d\u7684\u60f3\u6cd5\u90fd\u53ef\u4ee5\u5728\u4e0b\u9762\u7559\u8a00\uff0c\u4e0b\u671f\u518d\u89c1\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904:http:\/\/www.olinone.com\/ HI\uff0c\u4eb2\u7231\u8bfb\u8005\u670b\u53cb\u4eec\uff0c\u53c8\u5230\u4e86\u535a\u5ba2\u66f4\u65b0\u7684\u65f6\u95f4\uff0c\u5728\u2026 <span class=\"read-more\"><a href=\"http:\/\/www.olinone.com\/?p=280\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/280"}],"collection":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=280"}],"version-history":[{"count":14,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/280\/revisions"}],"predecessor-version":[{"id":789,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/280\/revisions\/789"}],"wp:attachment":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}