Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GLCircleScrollVeiw/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
50 changes: 25 additions & 25 deletions GLCircleScrollVeiw/CirCleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import UIKit

let TimeInterval = 2.5 //全局的时间间隔

class CirCleView: UIView, UIScrollViewDelegate {
public class CirCleView: UIView, UIScrollViewDelegate {
/*********************************** Property ****************************************/
//MARK:- Property -

var contentScrollView: UIScrollView!

var imageArray: [UIImage!]! {
public var imageArray: [UIImage!]! {
//监听图片数组的变化,如果有变化立即刷新轮转图中显示的图片
willSet(newValue) {
self.imageArray = newValue
Expand All @@ -40,18 +40,18 @@ 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)
}
}
}

var delegate: CirCleViewDelegate?
public var delegate: CirCleViewDelegate?

var indexOfCurrentImage: Int! { // 当前显示的第几张图片
//监听显示的第几张图片,来更新分页指示器
Expand All @@ -71,11 +71,11 @@ 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

Expand All @@ -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")
}

Expand All @@ -102,24 +102,24 @@ 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
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()
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)
Expand Down Expand Up @@ -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{
Expand All @@ -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)
}

Expand All @@ -179,22 +179,22 @@ 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 {
self.scrollViewDidEndDecelerating(scrollView)
}
}

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 {
Expand All @@ -212,22 +212,22 @@ class CirCleView: UIView, UIScrollViewDelegate {
}

//时间触发器 设置滑动时动画true,会触发的方法
func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
print("animator")
public func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
// print("animator", terminator: "")
self.scrollViewDidEndDecelerating(contentScrollView)
}


}


@objc protocol CirCleViewDelegate {
@objc public protocol CirCleViewDelegate {
/**
* 点击图片的代理方法
*
* @para currentIndxe 当前点击图片的下标
* @para currentIndex 当前点击图片的下标
*/
optional func clickCurrentImage(currentIndxe: Int)
optional func clickCurrentImage(currentIndex: Int)
}


Expand Down
6 changes: 3 additions & 3 deletions GLCircleScrollVeiw/FirstVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -55,7 +55,7 @@ class FirstVC: UIViewController, CirCleViewDelegate {
//MARK:- CirCleViewDelegate Methods

func clickCurrentImage(currentIndxe: Int) {
print(currentIndxe);
print(currentIndxe, terminator: "");
}


Expand Down
11 changes: 11 additions & 0 deletions GLCircleScrollView.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Pod::Spec.new do |s|
s.name = "GLCircleScrollView"
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.1"}
s.platform = :ios, '8.0'
s.source_files = 'GLCircleScrollVeiw/CirCleView.swift'
end
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
---

*这个基本上是最简单的版本了,后续会添加一些其他的功能*