IOS引导页面测试

转载:http://www.jianshu.com/p/024dd2d6e6e6#




import UIKit

class ViewController: UIViewController {
    //storyboard里面的开始按钮
    @IBOutlet weak var startButton: UIButton!
    //storyboard里面的
    @IBOutlet weak var pageCon: UIPageControl!
    // 新建UIScrollView
    private var scrollView: UIScrollView!
    // UIScrollView的滚动数量
    private let numOfPages = 3
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        //获取vc大小
        let frame = self.view.bounds
        //大小
        scrollView = UIScrollView(frame: frame)
        
        scrollView.pagingEnabled = true
        
        scrollView.showsHorizontalScrollIndicator = false
        
        scrollView.showsVerticalScrollIndicator = false
        
        scrollView.scrollsToTop = false
        //滑动到首尾的弹性效果
        scrollView.bounces = false
        
        scrollView.contentOffset = CGPointZero
        // 将 scrollView 的 contentSize 设为屏幕宽度的3倍(根据实际情况改变)
        scrollView.contentSize = CGSize(width: frame.size.width * CGFloat(numOfPages), height: frame.size.height)
        //滑动的代理
        scrollView.delegate = self
        //设置导航的页面
        for index  in 0.. Bool {
        return true
    }
}

// MARK: - UIScrollViewDelegate
extension ViewController: UIScrollViewDelegate {
    func scrollViewDidScroll(scrollView: UIScrollView) {
        //滑动的当前页面
        let offset = scrollView.contentOffset
        // 随着滑动改变pageControl的状态
        pageCon.currentPage = Int(offset.x / view.bounds.width)
        
        // 因为currentPage是从0开始,所以numOfPages减1
        if pageCon.currentPage == numOfPages - 1 {
            UIView.animateWithDuration(0.5) {
                self.startButton.alpha = 1.0
            }
        } else {
            UIView.animateWithDuration(0.2) {
                self.startButton.alpha = 0.0
            }
        }
    }
}

你可能感兴趣的:(IOS引导页面测试)