启动引导页

//

//  AppDelegate.swift

//  FlowerField

//

//  Created by CJW on 17/6/5.

//  Copyright © 2017 cjw. All rights reserved.

//


import UIKit


@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {


    var window: UIWindow?



    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        // Override point for customization after application launch.

        

        // 设置全局的UINavigationBars属性

        let bar = UINavigationBar.appearance()

        bar.tintColor = UIColor.redColor()

        bar.titleTextAttributes = [NSFontAttributeName:UIFont.systemFontOfSize(15),NSForegroundColorAttributeName:UIColor.blackColor()]

        window = UIWindow(frame: UIScreen.mainScreen().bounds)

        window?.backgroundColor = UIColor.whiteColor()

        // 根据版本号,判断显示哪个控制器

        if toNewFeature() {

            window?.rootViewController = NewFeatureViewController()

        }else {

            window?.rootViewController = MainViewController()

        }

        window?.makeKeyAndVisible()

        

        return true

    }

     private let XCBundleShortVersionString = "XCBundleShortVersionString"

    // MARK: - 判断版号

    private func toNewFeature() -> Bool {

        // 根据版本号来确定是否进入新特性界面

        let currentVersion = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String

        let oldVersion = NSUserDefaults.standardUserDefaults().objectForKey(XCBundleShortVersionString) ?? ""

         // 如果当前的版本号和本地保存的版本比较是降序, 则需要显示新特性

        if (currentVersion.compare(oldVersion as! String)) == .OrderedDescending{

            //保存当前版本

            NSUserDefaults.standardUserDefaults().setObject(currentVersion, forKey: XCBundleShortVersionString)

            return true

        }

        return false

    }

}


//

//  NewFeatureViewController.swift

//  FlowerField

//

//  Created by CJW on 17/6/5.

//  Copyright © 2017 cjw. All rights reserved.

//


import UIKit

import SnapKit


private let reuseIdentifier = "reuseIdentifier"


class NewFeatureViewController: UICollectionViewController {


    //MARK: - 生命周期方法

    init() {

        super.init(collectionViewLayout:newFeatureFlowLayout())

    }

    

    required init?(coder aDecoder: NSCoder) {

        fatalError("init(coder:) has not been implemented")

    }

    

    override func viewDidLoad() {

        super.viewDidLoad()

          setup()

    }

    private func setup() {

          //注册CELL

          self.collectionView!.registerClass(NewFeatureCell.self, forCellWithReuseIdentifier: reuseIdentifier)

          // 添加pageControll

         collectionView?.addSubview(pageControll)

        

        // 布局

        pageControll.snp_makeConstraints { (make) in

            make.bottom.equalTo(self.view).offset(-10)

            make.centerX.equalTo(self.view)

            make.size.equalTo(CGSize(width: 100, height: 20))

        }

  

    }


    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }


    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        // #warning Incomplete implementation, return the number of items

        return imageNames.count ?? 0

    }


    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

        let cell:NewFeatureCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! NewFeatureCell

    

        let count = imageNames.count ?? 0

        if count > 0 {

            cell.image = UIImage(named: imageNames[indexPath.item])

        }

        // Configure the cell

    

        return cell

    }

    override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

        // 能进入这儿,imageNames.count肯定有值了

        if indexPath.item == imageNames.count - 1 {

            keyWindow.rootViewController = MainViewController()

        }

    }

    

    override func scrollViewDidEndDecelerating(scrollView: UIScrollView) {

        let currendPage = Int(scrollView.contentOffset.x / self.view.bounds.width + 0.5)

        //最后一页不显示pageControll

        pageControll.currentPage = currendPage

    }

    override func scrollViewDidScroll(scrollView: UIScrollView) {

        if scrollView.contentOffset.x/self.view.bounds.width > (CGFloat(imageNames.count)-1.5){

            pageControll.hidden = true

        }else {

            pageControll.hidden = false

        }

    }

    

    

    // MARK: -懒加载

    /// 新特性的图片数组

    private let imageNames:[String] = ["gp_bg_0","gp_bg_1", "gp_bg_2"]

    /// pageControll

    private lazy var pageControll:UIPageControl = {

        let pageContr = UIPageControl()

        pageContr.numberOfPages = self.imageNames.count ?? 0

        pageContr.pageIndicatorTintColor = UIColor.whiteColor()

        pageContr.currentPageIndicatorTintColor = UIColor.yellowColor()

        return pageContr

    }()


}


class newFeatureFlowLayout: UICollectionViewFlowLayout {

    override func prepareLayout() {

        super.prepareLayout()

        // MARK: 设置layout

        // 设置itemSize

        itemSize = UIScreen.mainScreen().bounds.size

        //设置间距

        minimumLineSpacing = 0

        minimumInteritemSpacing = 0

        //设置方向

        scrollDirection = .Horizontal

        

        // MARK: 设置collectionVIew

        // 设置分页

        collectionView?.pagingEnabled = true

        // 设置隐藏横竖的滚动条

        collectionView?.showsVerticalScrollIndicator = false

        collectionView?.showsHorizontalScrollIndicator = false

        //取消弹簧效果

        collectionView?.bounces = false

    }

}



//

//  NewFeatureCell.swift

//  FlowerField

//

//  Created by CJW on 17/6/5.

//  Copyright © 2017 cjw. All rights reserved.

//


import UIKit

import SnapKit


class NewFeatureCell: UICollectionViewCell {

    //显示的image

    var image:UIImage?{

        didSet {

            if let img = image {

                imageView.image = img

            }

        }

    }

    

    // MARK : - 内部控制方法

    override init(frame: CGRect) {

        super.init(frame:frame)

        setup()

    }

    

    required init?(coder aDecoder: NSCoder) {

        fatalError("init(coder:) has not been implemented")

    }

    private func setup(){

        contentView.addSubview(imageView)

        imageView.snp_makeConstraints { (make) in

            make.edges.equalTo(0)

        }

    }

    

    // MARK: - 懒加载

    private lazy var imageView:UIImageView = UIImageView()


}

















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值