{"id":13696930,"url":"https://github.com/mengxianliang/XLCardSwitch","last_synced_at":"2025-05-03T17:32:40.887Z","repository":{"id":113372088,"uuid":"78172500","full_name":"mengxianliang/XLCardSwitch","owner":"mengxianliang","description":"iOS 利用余弦函数特性实现可以居中放大的图片浏览工具","archived":false,"fork":false,"pushed_at":"2021-11-11T09:51:35.000Z","size":18901,"stargazers_count":391,"open_issues_count":1,"forks_count":75,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-07T11:07:10.808Z","etag":null,"topics":["card","scale","scroll","switch"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mengxianliang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-01-06T04:04:30.000Z","updated_at":"2024-10-30T07:31:02.000Z","dependencies_parsed_at":"2023-06-15T11:30:18.430Z","dependency_job_id":null,"html_url":"https://github.com/mengxianliang/XLCardSwitch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mengxianliang%2FXLCardSwitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mengxianliang%2FXLCardSwitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mengxianliang%2FXLCardSwitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mengxianliang%2FXLCardSwitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mengxianliang","download_url":"https://codeload.github.com/mengxianliang/XLCardSwitch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224369821,"owners_count":17299961,"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":["card","scale","scroll","switch"],"created_at":"2024-08-02T18:00:50.154Z","updated_at":"2024-11-13T00:31:12.849Z","avatar_url":"https://github.com/mengxianliang.png","language":"Swift","funding_links":[],"categories":["UI Components"],"sub_categories":[],"readme":"# XLCardSwitch\n\n利用余弦函数的曲线特性实现的图片居中放大浏览工具，内部是利用UICollectionview的滚动实现的，有兴趣的可以看一下我的博文，里面有具体的实现原理，还是挺好玩儿的。本工具也只是想传递这个这个居中放大的算法，为了方便使用也做了些功能性的封装；\n\n## 功能\n\n- [x] 手指拖动切换卡片\n- [x] 调用方法切换卡片\n- [x] 可设置分页滚动\n\n## 效果 \n\n|正常滚动|自动居中|调用方法切换|\n|:---:|:---:|:---:|\n|![image](https://github.com/mengxianliang/ImageRepository/blob/master/XLCardSwitch/GIF/1.gif)|![image](https://github.com/mengxianliang/ImageRepository/blob/master/XLCardSwitch/GIF/2.gif)|![image](https://github.com/mengxianliang/ImageRepository/blob/master/XLCardSwitch/GIF/3.gif)|\n\n## 使用方法 \n\n### OC版本\n\n**创建方法:**\n\n```objc\n    //设置卡片浏览器\n    _cardSwitch = [[XLCardSwitch alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64)];\n    _cardSwitch.items = items;\n    //设置代理\n    _cardSwitch.delegate = self;\n    //设置是否打开分页滑动\n    _cardSwitch.pagingEnabled = true;\n    //设置初始位置，默认为0\n    _cardSwitch.selectedIndex = 3;\n    [self.view addSubview:_cardSwitch];\n```\n\n**切换位置:**\n\n```objc\n[_cardSwitch switchToIndex:3 animated:true];\n```\n或\n```objc\n_cardSwitch.selectedIndex = 3;\n```\n\n**代理方法:**\n\n```objc\n- (void)XLCardSwitchDidSelectedAt:(NSInteger)index {\n    NSLog(@\"选中了：%zd\",index);\n}\n```\n\n### Swift版本\n\n\n#### 1、创建\n\n```swift\nlazy var cardSwitch: XLCardSwitch = {\n    let temp = XLCardSwitch.init()\n    temp.frame = self.view.bounds\n    temp.dataSource = self\n    temp.delegate = self\n    //注册cell\n    temp.register(cellClass: CustomCollectionViewCell.self, forCellWithReuseIdentifier:\"CustomCellID\")\n    return temp\n}()\n```\n\n#### 2、DataSource\n\n*注：使用时必须接入DataSource方法，且需要自定义一个UICollectionviewcell，使用方法和UICollectionview一样，先注册，再使用；XLCardSwitch只负责缩放效果，不关心其他数据和UI*\n\n```swift\n//DataSource方法，返回总共卡片个数\nfunc cardSwitchNumberOfCard() -\u003e (Int) {\n    return self.cellInfoArr().count\n}\n    \n//DataSource方法，返回UICollectionViewCell\nfunc cardSwitchCellForItemAtIndex(index: Int) -\u003e (UICollectionViewCell) {\n    let cell = self.cardSwitch.dequeueReusableCell(withReuseIdentifier:\"CustomCellID\", for: index) as! CustomCollectionViewCell\n    cell.imageView.image = UIImage.init(named: self.cellInfoArr()[index].0)\n    cell.textLabel.text = self.cellInfoArr()[index].1\n    return cell\n}\n```\n\n#### 3、Delegate\n\n```swift\n//滑动切换到新的位置回调\n@objc optional func cardSwitchDidScrollToIndex(index: Int) -\u003e ()\n//手动点击了\n@objc optional func cardSwitchDidSelectedAtIndex(index: Int) -\u003e ()\n```\n\n### 实现原理请参考[我的博文](http://blog.csdn.net/u013282507/article/details/54136812) \n\n### 个人开发过的UI工具集合 [XLUIKit](https://github.com/mengxianliang/XLUIKit)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmengxianliang%2FXLCardSwitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmengxianliang%2FXLCardSwitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmengxianliang%2FXLCardSwitch/lists"}