{"id":24698293,"url":"https://github.com/dulingkang/sscyclescrollview","last_synced_at":"2025-06-15T14:31:08.737Z","repository":{"id":62454407,"uuid":"46558384","full_name":"dulingkang/SSCycleScrollView","owner":"dulingkang","description":"轮播终结者，用swift完成，易用集成","archived":false,"fork":false,"pushed_at":"2018-07-26T01:51:37.000Z","size":1391,"stargazers_count":39,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-29T08:07:17.917Z","etag":null,"topics":["pod","scroll","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dulingkang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-20T11:32:13.000Z","updated_at":"2022-03-26T09:09:57.000Z","dependencies_parsed_at":"2022-11-01T22:32:42.040Z","dependency_job_id":null,"html_url":"https://github.com/dulingkang/SSCycleScrollView","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/dulingkang/SSCycleScrollView","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulingkang%2FSSCycleScrollView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulingkang%2FSSCycleScrollView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulingkang%2FSSCycleScrollView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulingkang%2FSSCycleScrollView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dulingkang","download_url":"https://codeload.github.com/dulingkang/SSCycleScrollView/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulingkang%2FSSCycleScrollView/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259990173,"owners_count":22942422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pod","scroll","swift"],"created_at":"2025-01-27T04:04:33.202Z","updated_at":"2025-06-15T14:31:08.626Z","avatar_url":"https://github.com/dulingkang.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"### swift首页轮播 轻量级\n- 轮播终结者，用swift完成，易于集成使用，下载图片使用了SDWebImage\n- 自己动手用swift写了一个，欢迎试用！\n- 效果图：\n\u003cdiv align=center\u003e\n\u003cimg src=\"https://github.com/dulingkang/SSCycleScrollView/blob/master/SSCycleScrollDemo/SSCycleScrollDemo/sscycle.gif\" width=\"210\" height=\"240\"/\u003e\n\u003c/div\u003e\n\n### 网上找了一些首页轮播，写的或多或少有一些问题，用着不舒服，自己用swift写了一个轮播控件，有如下特点：\n\u003e * 下载图片使用了SDWebImage，性能高\n\u003e * 轮播图上需要点击链接，只需要调用一个block便可加上点击，易于集成\n\u003e * 支持webp格式图片，由于加入支持webp，电脑需要翻墙才能安装，[电脑更改hosts在这儿](https://github.com/dulingkang/host)\n\n### 使用方法\n在Podfile加入以下：\n\n```\nuse_frameworks!\npod 'SSCycleScrollView'\n```\n这个库中支持了webp格式图片，引入了SDWebImage库。\n下面可参考Demo中：\n初始化时，传一个url的array，可以传本地的图片名字，也可以传网络图片;\nv2.1.0中为了引入网络图片的placeholderImage，此array改成了如下样式：\n```\nvar scrollImageUrls: [[String]] {\n        get {\n            return [[\"https://devthinking.com/images/wechatqcode.jpg\", \"banner4.jpg\"],\n                    [\"banner1.jpg\"],\n                    [\"banner3.jpg\"]]\n        }\n    }\n```\n\n初始化一个SSCycleScrollView:\n\n```\n        self.mainScrollView = SSCycleScrollView.init(frame: currentRect, animationDuration: 3, inputImageUrls: self.scrollImageUrls)\n        self.mainScrollView?.tapBlock = {index in\n            print(\"tapped page\\(index)\")\n        }\n\n```\nautoScroll默认为true，如只需要手动滚动，需要：\n```\n       self.mainScrollView?.autoScroll = false\n```\n### 原理SSCycleScrollView\n初始化后会启动一个定时器，repeat调用一个timerFired方法，方法中每次对scrollview加一个自己宽度的offset:\n\n```\nfunc timerFired() {\nlet xOffset = Int(self.contentOffset.x/kScreenWidth)\nlet xOffsetFloat = CGFloat(xOffset) * kScreenWidth\nlet newOffset = CGPointMake(xOffsetFloat + CGRectGetWidth(self.frame), self.contentOffset.y)\nself.setContentOffset(newOffset, animated: true)\n}\n```\n\n没有直接加xOffset, 而是对其做了一个换算，确保每次加的offset是自己宽度的整数倍。\n在scrollViewDidScroll方法，每次计算前一个，当前，后一个index，确保index范围为index \u003e= 0 \u0026\u0026 index \u003c allImageArray.count, 每次滚动后都会三个imageView中的image做重新赋值：\n\n```\nself.previousDisplayView?.image = self.allImageArray[previousArrayIndex]\nself.currentDisplayView?.image = self.allImageArray[self.currentArrayIndex]\nself.lastDisplayView?.image = self.allImageArray[lastArrayIndex]\nself.contentOffset = CGPointMake(CGRectGetWidth(self.frame), 0)\n```\n\n上面最后一行设置contenOffset非常重要，每次把scrollView的位置重置为1个自身宽度的offset。\n\n### 小结\n如果你觉得有不好的地方，可以提出来，大家一块研究一下，欢迎常来我的[仓库](https://github.com/dulingkang/)，别忘记给个star！\n\n### 微信公众号\n\n\u003cdiv align=center\u003e\n\u003cimg src=\"http://upload-images.jianshu.io/upload_images/844885-6ede66cdf2a3c46e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" width=\"180\" height=\"180\" alt=\"开发者思维 devthinking\"/\u003e\n\u003c/div\u003e\n\n### QQ交流群：295976280\n\n\u003cdiv align=center\u003e\n\u003cimg src=\"http://upload-images.jianshu.io/upload_images/844885-0b4506f56fb77b47.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" width=\"180\" height=\"220\" alt=\"iOS交流群（一）群二维码\"/\u003e\n\u003c/div\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdulingkang%2Fsscyclescrollview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdulingkang%2Fsscyclescrollview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdulingkang%2Fsscyclescrollview/lists"}