From 1aace24d2c7d92bd1c8abc84f080982b40acbfce Mon Sep 17 00:00:00 2001 From: mouseshi Date: Sat, 10 Oct 2015 17:14:54 +0800 Subject: [PATCH 01/10] fix typo --- GLCircleScrollVeiw/CirCleView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GLCircleScrollVeiw/CirCleView.swift b/GLCircleScrollVeiw/CirCleView.swift index 657f24c..f642e43 100644 --- a/GLCircleScrollVeiw/CirCleView.swift +++ b/GLCircleScrollVeiw/CirCleView.swift @@ -225,9 +225,9 @@ class CirCleView: UIView, UIScrollViewDelegate { /** * 点击图片的代理方法 * - * @para currentIndxe 当前点击图片的下标 + * @para currentIndex 当前点击图片的下标 */ - optional func clickCurrentImage(currentIndxe: Int) + optional func clickCurrentImage(currentIndex: Int) } From f8c754523490b6f972ed32c41aba9d1347bd67f5 Mon Sep 17 00:00:00 2001 From: mouseshi Date: Sat, 10 Oct 2015 17:21:53 +0800 Subject: [PATCH 02/10] modify README --- README.md | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index cdf2453..7de3751 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,39 @@ # GLCircleScrollView +--- + 无限循环轮播图 -* GLCircleScrollView 有以下主要功能: +### GLCircleScrollView 有以下主要功能: +--- + + * 无限循环轮播 + + * 图片点击代理 + + * 可设置图片Url的数组(如果要赋url数组的话,最好自己改成sd加载图片的方式) + +### 截图 +--- + +![](https://github.com/god-long/GLCircleScrollView/raw/master/Circle.gif) - > 无限循环轮播 - - > 图片点击代理 - - > 可设置图片Url的数组(如果要赋url数组的话,最好自己改成sd加载图片的方式) +### 使用方法: +--- + 下载后直接把CirCleView.swift这个文件引入项目中 - ![](https://github.com/god-long/GLCircleScrollView/raw/master/Circle.gif) +* 简单代码例子 - -* 使用方法: +```swift + var imageArray: [UIImage!] = [UIImage(named: "first.jpg"), UIImage(named: "second.jpg"), UIImage(named: "third.jpg")] + self.circleView = CirCleView(frame: CGRectMake(0, 64, self.view.frame.size.width, 200), imageArray: imageArray) + circleView.backgroundColor = UIColor.orangeColor() + circleView.delegate = self + self.view.addSubview(circleView) +``` - > 下载后直接把CirCleView.swift这个文件拉进项目中即可。 - +### TODO +--- *这个基本上是最简单的版本了,后续会添加一些其他的功能* From 6c61b64b512553b98168b4d929c821c1c91cb5a6 Mon Sep 17 00:00:00 2001 From: mouseshi Date: Mon, 12 Oct 2015 11:54:28 +0800 Subject: [PATCH 03/10] add pod file --- GLCircleScrollView.podspec | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 GLCircleScrollView.podspec diff --git a/GLCircleScrollView.podspec b/GLCircleScrollView.podspec new file mode 100644 index 0000000..d7cb84f --- /dev/null +++ b/GLCircleScrollView.podspec @@ -0,0 +1,12 @@ +Pod::Spec.new do |s| + s.name = "GLCircleScrollView" + s.version = "1.0.0" + s.summary = "无限循环轮播图" + s.homepage = "https://github.com/mouse-lin/GLCircleScrollView" + s.license = { type: 'UA', file: 'LICENSE' } + s.author = "god-long" + s.source = { git: "https://github.com/mouse-lin/GLCircleScrollView.git", tags: "1.0.0"} + s.platform = :ios, '8.0' + s.source_files = 'Classes/*' + s.requires_arc = true +end From 58b01585e7bb2649464407833e70a24bd6bd1eca Mon Sep 17 00:00:00 2001 From: mouseshi Date: Mon, 12 Oct 2015 12:00:13 +0800 Subject: [PATCH 04/10] add LICENSE --- LICENSE | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..72dc60d --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. From f01749ee5ee7358cec680f806c7b6718802cad0c Mon Sep 17 00:00:00 2001 From: mouseshi Date: Mon, 12 Oct 2015 13:55:48 +0800 Subject: [PATCH 05/10] modify podspec file --- GLCircleScrollView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GLCircleScrollView.podspec b/GLCircleScrollView.podspec index d7cb84f..debece2 100644 --- a/GLCircleScrollView.podspec +++ b/GLCircleScrollView.podspec @@ -7,6 +7,6 @@ Pod::Spec.new do |s| s.author = "god-long" s.source = { git: "https://github.com/mouse-lin/GLCircleScrollView.git", tags: "1.0.0"} s.platform = :ios, '8.0' - s.source_files = 'Classes/*' + s.source_files = 'GLCircleScrollVeiw/CirCleView.swift' s.requires_arc = true end From fa23c13ac44d0d3af7f13b4a8dfdc4eb85d237c0 Mon Sep 17 00:00:00 2001 From: mouseshi Date: Mon, 12 Oct 2015 14:30:27 +0800 Subject: [PATCH 06/10] convert code to new swift style, set CirCleView public class --- GLCircleScrollVeiw/AppDelegate.swift | 4 ++-- GLCircleScrollVeiw/CirCleView.swift | 30 ++++++++++++++-------------- GLCircleScrollVeiw/FirstVC.swift | 6 +++--- GLCircleScrollView.podspec | 3 +-- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/GLCircleScrollVeiw/AppDelegate.swift b/GLCircleScrollVeiw/AppDelegate.swift index 0bf87b3..e18cf37 100644 --- a/GLCircleScrollVeiw/AppDelegate.swift +++ b/GLCircleScrollVeiw/AppDelegate.swift @@ -20,8 +20,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { self.window?.backgroundColor = UIColor.whiteColor() self.window?.makeKeyAndVisible() - var firstVC = FirstVC() - var naviVC = UINavigationController(rootViewController: firstVC) + let firstVC = FirstVC() + let naviVC = UINavigationController(rootViewController: firstVC) self.window?.rootViewController = naviVC diff --git a/GLCircleScrollVeiw/CirCleView.swift b/GLCircleScrollVeiw/CirCleView.swift index f642e43..505a1d1 100644 --- a/GLCircleScrollVeiw/CirCleView.swift +++ b/GLCircleScrollVeiw/CirCleView.swift @@ -10,7 +10,7 @@ import UIKit let TimeInterval = 2.5 //全局的时间间隔 -class CirCleView: UIView, UIScrollViewDelegate { +public class CirCleView: UIView, UIScrollViewDelegate { /*********************************** Property ****************************************/ //MARK:- Property - @@ -40,11 +40,11 @@ class CirCleView: UIView, UIScrollViewDelegate { didSet { //这里用了强制拆包,所以不要把urlImageArray设为nil for urlStr in self.urlImageArray! { - var urlImage = NSURL(string: urlStr) + let urlImage = NSURL(string: urlStr) if urlImage == nil { break } - var dataImage = NSData(contentsOfURL: urlImage!) + let dataImage = NSData(contentsOfURL: urlImage!) if dataImage == nil { break } - var tempImage = UIImage(data: dataImage!) + let tempImage = UIImage(data: dataImage!) if tempImage == nil { break } imageArray.append(tempImage) } @@ -84,7 +84,7 @@ class CirCleView: UIView, UIScrollViewDelegate { self.setUpCircleView() } - required init(coder aDecoder: NSCoder) { + required public init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -109,7 +109,7 @@ class CirCleView: UIView, UIScrollViewDelegate { contentScrollView.addSubview(currentImageView) //添加点击事件 - var imageTap = UITapGestureRecognizer(target: self, action: Selector("imageTapAction:")) + let imageTap = UITapGestureRecognizer(target: self, action: Selector("imageTapAction:")) currentImageView.addGestureRecognizer(imageTap) self.lastImageView = UIImageView() @@ -147,7 +147,7 @@ class CirCleView: UIView, UIScrollViewDelegate { // 得到上一张图片的下标 private func getLastImageIndex(indexOfCurrentImage index: Int) -> Int{ - var tempIndex = index - 1 + let tempIndex = index - 1 if tempIndex == -1 { return self.imageArray.count - 1 }else{ @@ -158,13 +158,13 @@ class CirCleView: UIView, UIScrollViewDelegate { // 得到下一张图片的下标 private func getNextImageIndex(indexOfCurrentImage index: Int) -> Int { - var tempIndex = index + 1 + let tempIndex = index + 1 return tempIndex < self.imageArray.count ? tempIndex : 0 } //事件触发方法 func timerAction() { - print("timer") + print("timer", terminator: "") contentScrollView.setContentOffset(CGPointMake(self.frame.size.width*2, 0), animated: true) } @@ -179,12 +179,12 @@ class CirCleView: UIView, UIScrollViewDelegate { /********************************** Delegate Methods ***************************************/ //MARK:- Delegate Methods //MARK:- UIScrollViewDelegate - - func scrollViewWillBeginDragging(scrollView: UIScrollView) { + public func scrollViewWillBeginDragging(scrollView: UIScrollView) { timer?.invalidate() timer = nil } - func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { + public func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { //如果用户手动拖动到了一个整数页的位置就不会发生滑动了 所以需要判断手动调用滑动停止滑动方法 if !decelerate { @@ -192,9 +192,9 @@ class CirCleView: UIView, UIScrollViewDelegate { } } - func scrollViewDidEndDecelerating(scrollView: UIScrollView) { + public func scrollViewDidEndDecelerating(scrollView: UIScrollView) { - var offset = scrollView.contentOffset.x + let offset = scrollView.contentOffset.x if offset == 0 { self.indexOfCurrentImage = self.getLastImageIndex(indexOfCurrentImage: self.indexOfCurrentImage) }else if offset == self.frame.size.width * 2 { @@ -212,8 +212,8 @@ class CirCleView: UIView, UIScrollViewDelegate { } //时间触发器 设置滑动时动画true,会触发的方法 - func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) { - print("animator") + public func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) { + print("animator", terminator: "") self.scrollViewDidEndDecelerating(contentScrollView) } diff --git a/GLCircleScrollVeiw/FirstVC.swift b/GLCircleScrollVeiw/FirstVC.swift index a12113b..62b3870 100644 --- a/GLCircleScrollVeiw/FirstVC.swift +++ b/GLCircleScrollVeiw/FirstVC.swift @@ -19,14 +19,14 @@ class FirstVC: UIViewController, CirCleViewDelegate { super.viewDidLoad() self.title = "CirCle" self.automaticallyAdjustsScrollViewInsets = false - var imageArray: [UIImage!] = [UIImage(named: "first.jpg"), UIImage(named: "second.jpg"), UIImage(named: "third.jpg")] + let imageArray: [UIImage!] = [UIImage(named: "first.jpg"), UIImage(named: "second.jpg"), UIImage(named: "third.jpg")] self.circleView = CirCleView(frame: CGRectMake(0, 64, self.view.frame.size.width, 200), imageArray: imageArray) circleView.backgroundColor = UIColor.orangeColor() circleView.delegate = self self.view.addSubview(circleView) - var tempButton = UIButton(frame: CGRectMake(0, 300, self.view.frame.size.width, 20)) + let tempButton = UIButton(frame: CGRectMake(0, 300, self.view.frame.size.width, 20)) tempButton.backgroundColor = UIColor.redColor() tempButton.setTitle("appendImage", forState: UIControlState.Normal) tempButton.addTarget(self, action: Selector("setImage:"), forControlEvents: UIControlEvents.TouchUpInside) @@ -55,7 +55,7 @@ class FirstVC: UIViewController, CirCleViewDelegate { //MARK:- CirCleViewDelegate Methods func clickCurrentImage(currentIndxe: Int) { - print(currentIndxe); + print(currentIndxe, terminator: ""); } diff --git a/GLCircleScrollView.podspec b/GLCircleScrollView.podspec index debece2..c283589 100644 --- a/GLCircleScrollView.podspec +++ b/GLCircleScrollView.podspec @@ -5,8 +5,7 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/mouse-lin/GLCircleScrollView" s.license = { type: 'UA', file: 'LICENSE' } s.author = "god-long" - s.source = { git: "https://github.com/mouse-lin/GLCircleScrollView.git", tags: "1.0.0"} + s.source = { git: "https://github.com/mouse-lin/GLCircleScrollView.git", tag: "1.0.0"} s.platform = :ios, '8.0' s.source_files = 'GLCircleScrollVeiw/CirCleView.swift' - s.requires_arc = true end From 015e55758468d34db1dad52206e9322951421f1a Mon Sep 17 00:00:00 2001 From: mouseshi Date: Mon, 12 Oct 2015 14:43:42 +0800 Subject: [PATCH 07/10] set init method public --- GLCircleScrollVeiw/CirCleView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GLCircleScrollVeiw/CirCleView.swift b/GLCircleScrollVeiw/CirCleView.swift index 505a1d1..d95d8fa 100644 --- a/GLCircleScrollVeiw/CirCleView.swift +++ b/GLCircleScrollVeiw/CirCleView.swift @@ -71,11 +71,11 @@ public class CirCleView: UIView, UIScrollViewDelegate { /*********************************** Begin ****************************************/ //MARK:- Begin - - override init(frame: CGRect) { + public override init(frame: CGRect) { super.init(frame: frame) } - convenience init(frame: CGRect, imageArray: [UIImage!]?) { + public convenience init(frame: CGRect, imageArray: [UIImage!]?) { self.init(frame: frame) self.imageArray = imageArray From 9a9697a70ba1904374f136c92849898142f2a143 Mon Sep 17 00:00:00 2001 From: mouseshi Date: Mon, 12 Oct 2015 16:56:06 +0800 Subject: [PATCH 08/10] set delegate public --- GLCircleScrollVeiw/CirCleView.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GLCircleScrollVeiw/CirCleView.swift b/GLCircleScrollVeiw/CirCleView.swift index d95d8fa..af023ae 100644 --- a/GLCircleScrollVeiw/CirCleView.swift +++ b/GLCircleScrollVeiw/CirCleView.swift @@ -16,7 +16,7 @@ public class CirCleView: UIView, UIScrollViewDelegate { var contentScrollView: UIScrollView! - var imageArray: [UIImage!]! { + public var imageArray: [UIImage!]! { //监听图片数组的变化,如果有变化立即刷新轮转图中显示的图片 willSet(newValue) { self.imageArray = newValue @@ -51,7 +51,7 @@ public class CirCleView: UIView, UIScrollViewDelegate { } } - var delegate: CirCleViewDelegate? + public var delegate: CirCleViewDelegate? var indexOfCurrentImage: Int! { // 当前显示的第几张图片 //监听显示的第几张图片,来更新分页指示器 @@ -164,7 +164,7 @@ public class CirCleView: UIView, UIScrollViewDelegate { //事件触发方法 func timerAction() { - print("timer", terminator: "") +// print("timer", terminator: "") contentScrollView.setContentOffset(CGPointMake(self.frame.size.width*2, 0), animated: true) } @@ -213,7 +213,7 @@ public class CirCleView: UIView, UIScrollViewDelegate { //时间触发器 设置滑动时动画true,会触发的方法 public func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) { - print("animator", terminator: "") +// print("animator", terminator: "") self.scrollViewDidEndDecelerating(contentScrollView) } @@ -221,7 +221,7 @@ public class CirCleView: UIView, UIScrollViewDelegate { } -@objc protocol CirCleViewDelegate { +@objc public protocol CirCleViewDelegate { /** * 点击图片的代理方法 * From 3eb2786fb16a50fc9d7a27bdf74b66e7bc7ebdc0 Mon Sep 17 00:00:00 2001 From: mouseshi Date: Wed, 28 Oct 2015 10:24:50 +0800 Subject: [PATCH 09/10] reset current last next UIImageView height --- GLCircleScrollVeiw/CirCleView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GLCircleScrollVeiw/CirCleView.swift b/GLCircleScrollVeiw/CirCleView.swift index af023ae..6f57c9c 100644 --- a/GLCircleScrollVeiw/CirCleView.swift +++ b/GLCircleScrollVeiw/CirCleView.swift @@ -102,7 +102,7 @@ public class CirCleView: UIView, UIScrollViewDelegate { self.addSubview(contentScrollView) self.currentImageView = UIImageView() - currentImageView.frame = CGRectMake(self.frame.size.width, 0, self.frame.size.width, 200) + currentImageView.frame = CGRectMake(self.frame.size.width, 0, self.frame.size.width, self.frame.size.height) currentImageView.userInteractionEnabled = true currentImageView.contentMode = UIViewContentMode.ScaleAspectFill currentImageView.clipsToBounds = true @@ -113,13 +113,13 @@ public class CirCleView: UIView, UIScrollViewDelegate { currentImageView.addGestureRecognizer(imageTap) self.lastImageView = UIImageView() - lastImageView.frame = CGRectMake(0, 0, self.frame.size.width, 200) + lastImageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) lastImageView.contentMode = UIViewContentMode.ScaleAspectFill lastImageView.clipsToBounds = true contentScrollView.addSubview(lastImageView) self.nextImageView = UIImageView() - nextImageView.frame = CGRectMake(self.frame.size.width * 2, 0, self.frame.size.width, 200) + nextImageView.frame = CGRectMake(self.frame.size.width * 2, 0, self.frame.size.width, self.frame.size.height) nextImageView.contentMode = UIViewContentMode.ScaleAspectFill nextImageView.clipsToBounds = true contentScrollView.addSubview(nextImageView) From 9ac6a4562b4440d8f33ed11da09aba86826b3599 Mon Sep 17 00:00:00 2001 From: mouseshi Date: Wed, 28 Oct 2015 10:26:27 +0800 Subject: [PATCH 10/10] update podspec --- GLCircleScrollView.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GLCircleScrollView.podspec b/GLCircleScrollView.podspec index c283589..7d49f1c 100644 --- a/GLCircleScrollView.podspec +++ b/GLCircleScrollView.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "GLCircleScrollView" - s.version = "1.0.0" + s.version = "1.0.1" s.summary = "无限循环轮播图" s.homepage = "https://github.com/mouse-lin/GLCircleScrollView" s.license = { type: 'UA', file: 'LICENSE' } s.author = "god-long" - s.source = { git: "https://github.com/mouse-lin/GLCircleScrollView.git", tag: "1.0.0"} + s.source = { git: "https://github.com/mouse-lin/GLCircleScrollView.git", tag: "1.0.1"} s.platform = :ios, '8.0' s.source_files = 'GLCircleScrollVeiw/CirCleView.swift' end