import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//增加標(biāo)識(shí),用于判斷是否是第一次啟動(dòng)應(yīng)用...
if (!(UserDefaults.standard.bool(forKey: "everLaunched"))) {
UserDefaults.standard.set(true, forKey:"everLaunched")
let guideViewController = GuideViewController()
self.window!.rootViewController=guideViewController;
print("guideview launched!")
}
return true
}
func applicationWillResignActive(_ application: UIApplication) {
}
func applicationDidEnterBackground(_ application: UIApplication) {
}
func applicationWillEnterForeground(_ application: UIApplication) {
}
func applicationDidBecomeActive(_ application: UIApplication) {
}
func applicationWillTerminate(_ application: UIApplication) {
}
}
import UIKit
class GuideViewController:UIViewController,UIScrollViewDelegate
{
//頁(yè)面數(shù)量
var numOfPages = 3
override func viewDidLoad()
{
let frame = self.view.bounds
//scrollView的初始化
let scrollView = UIScrollView()
scrollView.frame = self.view.bounds
scrollView.delegate = self
//為了能讓內(nèi)容橫向滾動(dòng),設(shè)置橫向內(nèi)容寬度為3個(gè)頁(yè)面的寬度總和
scrollView.contentSize = CGSize(width:frame.size.width * CGFloat(numOfPages),
height:frame.size.height)
print("\(frame.size.width*CGFloat(numOfPages)),\(frame.size.height)")
scrollView.isPagingEnabled = 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 = CGRect(x:frame.size.width*CGFloat(i), y:CGFloat(0),
width:frame.size.width, height:frame.size.height)
scrollView.addSubview(imgView)
}
scrollView.contentOffset = CGPoint.zero
self.view.addSubview(scrollView)
}
//scrollview滾動(dòng)的時(shí)候就會(huì)調(diào)用
func scrollViewDidScroll(_ scrollView: UIScrollView)
{
print("scrolled:\(scrollView.contentOffset)")
let twidth = CGFloat(numOfPages-1) * self.view.bounds.size.width
//如果在最后一個(gè)頁(yè)面繼續(xù)滑動(dòng)的話就會(huì)跳轉(zhuǎn)到主頁(yè)面
if(scrollView.contentOffset.x > twidth)
{
let mainStoryboard = UIStoryboard(name:"Main", bundle:nil)
let viewController = mainStoryboard.instantiateInitialViewController()
self.present(viewController!, animated: true, completion:nil)
}
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者