import UIKit
class GuideViewController:UIViewController,UIScrollViewDelegate
{
var numOfPages = 3
override func viewDidLoad()
{
let frame = self.view.bounds
let scrollView = UIScrollView()
scrollView.frame = self.view.bounds
scrollView.delegate = self
scrollView.contentSize = CGSizeMake(frame.size.width * CGFloat(numOfPages),
frame.size.height)
print("\(frame.size.width*CGFloat(numOfPages)),\(frame.size.height)")
scrollView.pagingEnabled = true
scrollView.showsHorizontalScrollIndicator = false
scrollView.showsVerticalScrollIndicator = false
scrollView.scrollsToTop = false
for i in 0..<numOfPages{
let imgfile = "jianjie\(Int(i+1)).png"
print(imgfile)
let image = UIImage(named:"\(imgfile)")
let imgView = UIImageView(image: image)
imgView.frame = CGRectMake(frame.size.width*CGFloat(i),CGFloat(0),
frame.size.width,frame.size.height)
scrollView.addSubview(imgView)
}
scrollView.contentOffset = CGPointZero
self.view.addSubview(scrollView)
}
func scrollViewDidScroll(scrollView: UIScrollView)
{
print("scrolled:\(scrollView.contentOffset)")
let twidth = CGFloat(numOfPages-1) * self.view.bounds.size.width
if(scrollView.contentOffset.x > twidth)
{
let mainStoryboard = UIStoryboard(name:"Main", bundle:nil)
let viewController = mainStoryboard.instantiateInitialViewController()
self.presentViewController(viewController!, animated: true, completion:nil)
}
}
}