分类 定时器 下的文章

模仿网易彩票

注意点:
1.在新建项目时,注意项目的目录结构
2.具有共同操作的类可以新建一个父类来完成公共的操作
3.把实现代码放在控制器类的不同生命周期时调用的方法中,可以避免做重复的操作
4.图片只显示某一部分
5.webView的使用
6.UICollectionViewController的使用
7.模态框的使用
8.自定义TabBarItem

1.目录结构就不说了,mvc
2.共同的父类,子类只要继承自父类,并完成自身的数据赋值即可
//
//  JinBaseTableViewController.swift
//  lottery
//
//  Created by admin on 16/2/4.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit
// 设置界面 UITableViewController 的父类,完成一些公共的操作
class JinBaseTableViewController: UITableViewController {
    // 存放设置选项模型数据
    var settings:[SettingGroup] = []
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.backgroundColor = UIColor(patternImage: UIImage(imageLiteral: "bg"))
    }

    // 重写构造方法,算是填了下坑吧
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName : nibNameOrNil, bundle : nibBundleOrNil)
    }
    override init(style: UITableViewStyle) {
        super.init(style: style)
        // 在这里设置背景色的话 viewDidload 方法会被调用两次
//        self.tableView.backgroundColor = UIColor(patternImage: UIImage(imageLiteral: "bg"))
    }
    required convenience init?(coder aDecoder: NSCoder) {
        //        fatalError("init(coder:) has not been implemented")
        self.init(style: UITableViewStyle.Grouped)
        //return nil
    }
    convenience init()
    {
        self.init(style: UITableViewStyle.Grouped)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return self.settings.count
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return self.settings[section].settings.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = JinTableViewCell.instance(tableView, setingData: self.settings[indexPath.section].settings[indexPath.row])
        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.settings[indexPath.section].settings[indexPath.row].block?()
    }
    override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return self.settings[section].title
    }
    override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
        return self.settings[section].footer
    }
}

子类代码

//
//  MyLotteryViewController.swift
//  lottery
//
//  Created by admin on 16/2/3.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class MyLotteryViewController: JinBaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationItem.title = "设置"

        let group1 = SettingGroup()
        group1.settings.append(Setting(title: "推送和提醒", titleImage: UIImage(imageLiteral: "handShake"), accessoryImage: UIImage(imageLiteral: "CellArrow"), block: {
            [unowned self] in
            let controller = PushAndRemindController()
            controller.navigationItem.title = "推送和提醒"
            self.navigationController?.pushViewController(controller, animated: true)
        }))

        group1.settings.append(Setting(title: "摇一摇机选", titleImage: UIImage(imageLiteral: "handShake"), accessory: UISwitch()))
        group1.settings.append(Setting(title: "声音和效果", titleImage: UIImage(imageLiteral: "handShake"), accessory: UISwitch()))
        self.settings.append(group1)
        let group2 = SettingGroup()
        group2.settings.append(Setting(title: "检查版本更新", titleImage: UIImage(imageLiteral: "handShake"), accessoryImage: UIImage(imageLiteral: "CellArrow"), block: {
                [unowned self] in
                let hud = MBProgressHUD.showHUDAddedTo(self.tableView, animated: true)
                hud.label.text = "正在检查更新"
                let time = dispatch_time(DISPATCH_TIME_NOW, Int64(UInt64(2) * NSEC_PER_SEC))
                dispatch_after(time, dispatch_get_main_queue(), {
                    let image = UIImage(imageLiteral: "Checkmark").imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
                    let imageView = UIImageView(image: image)
                    hud.customView = imageView
                    hud.mode = MBProgressHUDMode.CustomView
                    hud.label.text = "已是最新版本"
                    hud.hideAnimated(true, afterDelay: 1)
                })
            }))
        group2.settings.append(Setting(title: "帮助", titleImage: UIImage(imageLiteral: "handShake"), accessoryImage: UIImage(imageLiteral: "CellArrow"), block: {
            [unowned self] in
            let controller = HelpViewController()
            // 因为是自定义的 UITabBarItem 所以这里设置了也无效
//            controller.hidesBottomBarWhenPushed = false
            controller.navigationItem.title = "帮助"

            self.navigationController?.pushViewController(controller, animated: true)
            }))
        group2.settings.append(Setting(title: "分享", titleImage: UIImage(imageLiteral: "handShake"), accessoryImage: UIImage(imageLiteral: "CellArrow")))
        group2.settings.append(Setting(title: "查看消息", titleImage: UIImage(imageLiteral: "handShake"), accessoryImage: UIImage(imageLiteral: "CellArrow")))
        group2.settings.append(Setting(title: "产品推荐", titleImage: UIImage(imageLiteral: "handShake"), accessoryImage: UIImage(imageLiteral: "CellArrow"), block: {
            [unowned self] in
            let controller = ProductViewController(collectionViewLayout : UICollectionViewFlowLayout())
            controller.navigationItem.title = "产品推荐"
            self.navigationController?.pushViewController(controller, animated: true)
            }))
        group2.settings.append(Setting(title: "投信", titleImage: UIImage(imageLiteral: "handShake"), accessoryImage: UIImage(imageLiteral: "CellArrow")))
        self.settings.append(group2)
    }

}
3.在控制器特定的生命周期做操作,可以避免重复的操作
//
//  JinNavigationController.swift
//  lottery
//
//  Created by admin on 16/2/3.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class JinNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 修改navgation标题栏的样式,在这里改也行,但是这个方法会执行多次,所以最好使用 initialize
//        self.navigationBar.setBackgroundImage(UIImage(imageLiteral: "NavBar64"), forBarMetrics: UIBarMetrics.Default)
//        self.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor(),NSFontAttributeName:UIFont.systemFontOfSize(20)]
        // Do any additional setup after loading the view.
    }
    override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return UIStatusBarStyle.LightContent
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    // 当类第一次创建的时候调用这个方法,避免执行多次
    override class func initialize()
    {
        // 获取UINavigationBar对象
        weak var nav = UINavigationBar.appearance()
        // 设置背景图片
        nav!.setBackgroundImage(UIImage(imageLiteral: "NavBar64"), forBarMetrics: UIBarMetrics.Default)
        // 设置字体属性
        nav!.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor(),NSFontAttributeName:UIFont.systemFontOfSize(20)]
        // 设置返回按钮颜色
        nav!.tintColor = UIColor.whiteColor()
    }
}
4.图片显示某一部分
//
//  SquareViewController.swift
//  lottery
//
//  Created by admin on 16/2/4.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class SquareViewController: UIViewController {
    @IBOutlet weak var wheel: UIImageView!
    var link:CADisplayLink!
    var highlightedButton:UIButton!
    override func viewDidLoad() {
        // 转盘背景图片
        let imageView = UIImageView(image: UIImage(imageLiteral: "LuckyBackground"))
        imageView.frame = self.view.bounds
        self.view.insertSubview(imageView, atIndex: 0)
        // 获得屏幕scale,之后截取图片的时候会用到,不然图片截取之后是不规则的
        let scale = UIScreen.mainScreen().scale
        // 获得选项按钮背景图片
        let strology = UIImage(imageLiteral: "LuckyAstrology")
        let strologyPressed = UIImage(imageLiteral: "LuckyAstrologyPressed")
        // 获得截取图片的宽度
        let buttonW = strology.size.width / 12
        // 获得选项按钮的宽度
        let buttonFrame = CGRectMake(0, 0, buttonW, wheel.bounds.size.width * 0.5)
        // 设置图层的anchorPoint的值,旋转是围绕这个点旋转的
        let buttonLayerAnchorPoint = CGPointMake(0.5, 1)
        // 选项按钮放倒转盘中
        for var i = 0;i < 12;i++
        {
            let button = JinButton(type: UIButtonType.Custom)
            button.tag = i + 1
            button.frame = buttonFrame
            button.layer.anchorPoint = buttonLayerAnchorPoint
            button.center = CGPointMake(self.wheel.bounds.size.width * 0.5, self.wheel.bounds.size.width * 0.5)
            // 从大图片中截取一部分作为当前按钮的背景图片
            var buttonImage = CGImageCreateWithImageInRect(strology.CGImage, CGRectMake(buttonW * CGFloat(i) * scale, 0, buttonW * scale, strology.size.height * scale))
            button.setImage(UIImage(CGImage: buttonImage!), forState: UIControlState.Normal)
            buttonImage = CGImageCreateWithImageInRect(strologyPressed.CGImage, CGRectMake(buttonW * CGFloat(i) * scale, 0, buttonW * scale, strology.size.height * scale))
            // 设置选中状态下的图片
            button.setImage(UIImage(CGImage: buttonImage!), forState: UIControlState.Selected)
            button.setBackgroundImage(UIImage(imageLiteral: "LuckyRototeSelected"), forState: UIControlState.Selected)
            // 设置当前按钮的transform
            button.transform = CGAffineTransformMakeRotation(CGFloat(M_PI) / 6 * CGFloat(i))
            // 禁用高亮
            button.adjustsImageWhenHighlighted = false

            button.addTarget(self, action: "choiceNumber:", forControlEvents: UIControlEvents.TouchDown)
            self.wheel.addSubview(button)
        }
        // 添加开始选号按钮
        let choiceNumberButton = UIButton(type: UIButtonType.Custom)
        let choiceNumberButtonImage = UIImage(imageLiteral: "LuckyCenterButton")
        choiceNumberButton.bounds = CGRectMake(0, 0, choiceNumberButtonImage.size.width, choiceNumberButtonImage.size.height)
        choiceNumberButton.setBackgroundImage(choiceNumberButtonImage, forState: UIControlState.Normal)
        choiceNumberButton.setBackgroundImage(UIImage(imageLiteral: "LuckyCenterButtonPressed"), forState: UIControlState.Highlighted)
        choiceNumberButton.addTarget(self, action: "choiceNumberButtonClicked", forControlEvents: UIControlEvents.TouchDown)
        choiceNumberButton.center = self.wheel.center
        self.view.addSubview(choiceNumberButton)
        self.timer()
    }
    // 开始定时器
    func timer()
    {
        self.link = CADisplayLink(target: self, selector: "startRotation")
        self.link.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
    }
    // 旋转
    func startRotation()
    {
        self.wheel.transform = CGAffineTransformRotate(self.wheel.transform, CGFloat(M_PI) * 0.001)
    }
    // 选项按钮点击事件
    func choiceNumber(button:UIButton)
    {
        self.highlightedButton?.selected = false
        button.selected = true
        self.highlightedButton = button
    }
    func choiceNumberButtonClicked()
    {
        self.link?.invalidate()
        self.link = nil
        self.view.userInteractionEnabled = false
        UIView.transitionWithView(self.wheel, duration: 3, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
                [unowned self] in
                self.wheel.transform = CGAffineTransformRotate(self.wheel.transform, CGFloat(M_PI * 0.9))
            }, completion: {
                [unowned self] bool in
                let tag = Int(arc4random_uniform(12)) + 1
                let button:UIButton = self.wheel.viewWithTag(tag) as! UIButton
                self.choiceNumber(button)
                self.view.userInteractionEnabled = true
                //这里设置下延时执行,之前没用过的一种方式,这个参数有一些特别,而且没有提示。。。。记录下
                let minseconds = 3 * Double(NSEC_PER_SEC)
                let dtime = dispatch_time(DISPATCH_TIME_NOW, Int64(minseconds))
                if self.link == nil
                {
                    dispatch_after(dtime, dispatch_get_main_queue(), { [unowned self] () -> Void in
                        self.timer()
                    })
                }
        })
    }
}
5.webView的使用
//
//  HtmlViewController.swift
//  lottery
//
//  Created by admin on 16/2/4.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class HtmlViewController: UIViewController,UIWebViewDelegate {
    weak var help:Help!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = self.help.title
        let webview = UIWebView(frame: UIScreen.mainScreen().bounds)
        webview.delegate = self
        // 获得html文件路径
        let path = NSBundle.mainBundle().pathForResource("help.html", ofType: nil)
        // 获得请求字串
        let request = NSURLRequest(URL: NSURL(fileURLWithPath: path!))
        // 使用webView加载html
        webview.loadRequest(request)
        // 因为是使用模态框加载的这个控制器,所以需要手动设置下返回按钮
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", style: UIBarButtonItemStyle.Plain, target: self, action: "back")
        // 把webView添加进视图
        self.view.addSubview(webview)
    }
    // 返回之前的控制器
    func back()
    {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    // webView代理方法,加载完成时调用
    func webViewDidFinishLoad(webView: UIWebView) {
        // 执行js代码
        let jsCode = "window.location.href='#\(self.help.id)'"
        webView.stringByEvaluatingJavaScriptFromString(jsCode)
    }
}
6.UICollectionViewController的使用
//
//  ProductViewController.swift
//  lottery
//
//  Created by admin on 16/2/4.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit
let collectionIdentifier = "jinCollectionCell"
class ProductViewController: UICollectionViewController {
    // 产品数据模型数组
    lazy var products:[Product] = Product.instanceOfFile()
    // 重写构造方法
    override init(collectionViewLayout layout: UICollectionViewLayout) {
        // cell的大小是通过Layout来控制
        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSizeMake(100, 120)
        super.init(collectionViewLayout : layout)
    }
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName : nibNameOrNil, bundle : nibBundleOrNil)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.collectionView?.backgroundColor = UIColor.whiteColor()
        // 和tableView不同的是,需要先注册cell
//        self.collectionView?.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: collectionIdentifier)
        self.collectionView?.registerNib(UINib(nibName: "JinCollectionCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: collectionIdentifier)
    }
    // 返回分组数
    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }
    // 返回分组数据条数
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.products.count
    }
    // 返回cell
    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        // 从缓冲池中获取cell
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(collectionIdentifier, forIndexPath: indexPath) as! JinCollectionCell
        cell.product = self.products[indexPath.row]
        return cell
    }
    override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        let appliction = UIApplication.sharedApplication()
        // 打开url
        appliction.openURL(NSURL(string: self.products[indexPath.row].url)!)
    }
}
7.模态框的使用
//
//  HelpViewController.swift
//  lottery
//
//  Created by admin on 16/2/4.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class HelpViewController: JinBaseTableViewController {
    var helps:[Help] = Help.instanceOfFile()
    override func viewDidLoad() {
        super.viewDidLoad()
        print(helps)
        let group1 = SettingGroup()
        helps.forEach({
            val in
            group1.settings.append(Setting(title: val.title!, accessoryImage: UIImage(imageLiteral: "CellArrow")))
        })

        self.settings.append(group1)
    }
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        // 创建要显示的控制器
        let html = HtmlViewController()
        html.help = self.helps[indexPath.row]
        // 创建导航控制器并把要显示的控制器作为根控制器
        let nav = UINavigationController(rootViewController: html)
        // 显示模态窗口
        self.presentViewController(nav, animated: true, completion: nil)
    }
}
8.自定义TabBarItem
//
//  JinTabBarItem.swift
//  lottery
//
//  Created by admin on 16/2/3.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit
// 自定义协议
@objc protocol JinTabBarItemDelegate
{
    optional func tabBarButtonClicked(index:Int)
}
// 自定义 tabbaritem 类
class JinTabBarItem: UIView {

    // 记录当前选中状态的按钮
    weak var selectedTabBarButton:UIButton!
    // 当前对象代理
    weak var tabBarButtonDelegate:JinTabBarItemDelegate!
    // 添加item按钮
    func addTabBarButton(normalImage:String,selectedImage:String)
    {
        let tabBarButton = UIButton(type: UIButtonType.Custom)
        // 设置图片
        tabBarButton.setBackgroundImage(UIImage(imageLiteral: normalImage), forState: UIControlState.Normal)
        tabBarButton.setBackgroundImage(UIImage(imageLiteral: selectedImage), forState: UIControlState.Selected)
        // 设置图片方法
        tabBarButton.addTarget(self, action: "changeTabBarButtonStatus:", forControlEvents: UIControlEvents.TouchDown)
        // button 没有 setHighlighted 方法啊  我去
        tabBarButton.adjustsImageWhenHighlighted = false
        self.addSubview(tabBarButton)
    }
    // 按钮被点击时的响应事件
    func changeTabBarButtonStatus(button:UIButton)
    {
        // 修改当前选中按钮状态
        self.selectedTabBarButton?.selected = false
        // 修改当前点击按钮状态
        button.selected = true
        // 修改当前被选中的按钮
        self.selectedTabBarButton = button
        // 执行代理方法
        self.tabBarButtonDelegate?.tabBarButtonClicked?(self.subviews.indexOf(button)!)
    }
    // 完成按钮的布局
    override func layoutSubviews() {
        // 获得当前的子按钮数量
        let buttonCount = self.subviews.count
        // 获得当前状态下按钮的宽度
        let buttonWidth = self.frame.size.width / CGFloat(buttonCount)
        for(var i = 0;i < buttonCount;i++)
        {
            let tabBarButton = self.subviews[i] as! UIButton
            // 默认第一个按钮为选中
            if i == 0
            {
                self.changeTabBarButtonStatus(tabBarButton)
            }
            // 设置按钮fram
            tabBarButton.frame = CGRectMake(CGFloat(i) * buttonWidth, 0, buttonWidth, self.frame.size.height)
        }
    }
}

代码网址:https://git.oschina.net/JinDev/lottory.git

图片轮播swift版本

有几个需要注意的地方,scallView的常用属性,代理的使用,定时器的使用,定时器不同模式的区别,UIPageControl的使用

//
//  ViewController.swift
//  图片轮播
//
//  Created by admin on 15/12/31.
//  Copyright © 2015年 jin. All rights reserved.
//

import UIKit
//遵循了UIScrollViewDelegate协议,作为scallView的代理
class ViewController: UIViewController,UIScrollViewDelegate{

    @IBOutlet weak var scallView: UIScrollView!
    @IBOutlet weak var pageControl: UIPageControl!
    var timer:NSTimer!
    override func viewDidLoad() {
        super.viewDidLoad()

        let w = scallView.frame.size.width
        let h = scallView.frame.size.height
        let colnum = 5
        for var i = 1;i <= colnum + 1;i++
        {
            var imageView:UIImageView = UIImageView()
            //多添加一个图片,让轮播效果更顺眼
            if i > colnum
            {
                imageView.image = UIImage(imageLiteral: "img_01")
            }
            else
            {
                imageView.image = UIImage(imageLiteral: "img_" + String(format: "%02i", i))
            }
            let x = CGFloat(i - 1) * w
            imageView.frame = CGRectMake(x, 0, w, h)
            scallView.addSubview(imageView)
        }

        //scallView可拖动区域的大小
        scallView.contentSize = CGSizeMake(CGFloat(colnum) * w, 0)
        scallView.showsHorizontalScrollIndicator = false//去掉横向滚动条
        scallView.pagingEnabled = true//打开分页
        //设置UIPageControl的点的个数
        pageControl.numberOfPages = column
        //设置scallView的代理
        scallView.delegate = self
        //设置活动分页的颜色
        pageControl.currentPageIndicatorTintColor = UIColor.redColor()
        //设置活动分页之外分页的颜色
        pageControl.pageIndicatorTintColor = UIColor.blackColor()
        //添加定时器,自动切换图片
        self.addTimer()

    }
    //图片切换
    func imageChange()
    {
        var coordinates:CGPoint = CGPoint(x: 0,y: 0)
        //为了从最后一张切换到第一张的时候不那么突兀,这里需要处理
        if pageControl.currentPage == 0 && scallView.contentOffset.x > 0
        {
            coordinates = CGPoint(x: 0, y: scallView.contentOffset.y)
            self.scallView.contentOffset = coordinates
        }
        coordinates = CGPoint(x: CGFloat(pageControl.currentPage + 1) * scallView.frame.size.width, y: scallView.contentOffset.y)
        //动画效果
        UIView.animateWithDuration(1, animations: {
            self.scallView.contentOffset = coordinates
        })
    }
    //添加定时器的方法
    func addTimer()
    {
        //初始化定时器
        self.timer = NSTimer(timeInterval: 3, target: self, selector: "imageChange", userInfo: nil, repeats: true)
        //获得当前消息循环
        var runLoop = NSRunLoop.currentRunLoop()
        //把定时器以默认模式添加进当前消息循环,分为两种模式
//        runLoop.addTimer(self.timer, forMode: NSDefaultRunLoopMode)
        runLoop.addTimer(self.timer, forMode: NSRunLoopCommonModes)

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    //scrollView代理方法,滚动时
    func scrollViewDidScroll(scrollView: UIScrollView) {
        //获得当前页数
        let currentPage = Int((scallView.contentOffset.x + (scallView.frame.size.width * 0.5)) / scallView.frame.size.width)
        //因为多加了一个图片,所以这里需要处理下
        if currentPage >= pageControl.numberOfPages
        {
            pageControl.currentPage = 0
        }
        else
        {
            pageControl.currentPage = currentPage
        }
    }
    //scallView代理方法,开始拖拽
    func scrollViewWillBeginDragging(scrollView: UIScrollView) {
        self.timer.invalidate()
    }
    //scallView代理方法,结束拖拽
    func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        //创建定时器并加入当前消息循环,默认模式
//        self.timer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "imageChange", userInfo: nil, repeats: true)
        self.addTimer()
    }

}