Swift-The Creation of the wizard page at startup (Novice boot)

Source: Internet
Author: User
Tags uikit

In many iOS products or some application version of the upgrade, novice guidance is a common feature, through the page left and right sliding, can clearly show some of the system's features. Production ideas are as follows:
1, how to detect the application is the first time to login to startWe can use the Nsuserdefaults class to solve this problem. The feature is not lost due to application shutdown, system restart. So it can be used to flag whether it has been started.
2, Novice boot View controller we use UiscrollviewFor example, we set a total of three new guide map, all added to Uiscrollview, then Uiscrollview content width is 3 times times the width of the photo or screen.
3, in order to adapt to different resolutions, need to design several sets of different dimensions of the diagramThe naming conventions for iOS picture resources are:basename + screen size modifier + urischeme + orientation + scale + device +. Extbasename: File namescreen size modifier: Display size modifier (IPhone5 appears after, such as -568h)Urischeme: A string that identifies the URI scheme (the general situation does not need to be concerned)Orientation: Screen orientation (horizontal screen is-landscape, vertical screen is-portrait)scale: Scaled size (normal screen does not need, retina screen for @2x,iphone6 after more than a @3x)Device: Equipment type (~ipad for ipad use). ext: File extension (can be PNG or other format)Although the file is complex, the call is simple, just write the basename.ext.
4, as follows:
5, the file structure is as follows:
6, Entry class: Appdelegate.swift
1234567891011121314151617181920212223242526272829303132333435 import UIKit@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {        var window: UIWindow?        func application(application: UIApplication,        didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {        // Override point for customization after application launch.        //增加标识,用于判断是否是第一次启动应用...        if (!(NSUserDefaults.standardUserDefaults().boolForKey("everLaunched"))) {            NSUserDefaults.standardUserDefaults().setBool(true, forKey:"everLaunched")            varguideViewController = GuideViewController()            self.window!.rootViewController=guideViewController;            println("guideview launched!")        }        return true    }        func applicationWillResignActive(application: UIApplication) {    }        func applicationDidEnterBackground(application: UIApplication) {    }        func applicationWillEnterForeground(application: UIApplication) {    }        func applicationDidBecomeActive(application: UIApplication) {    }        func applicationWillTerminate(application: UIApplication) {    }}

7, Wizard page: Guideviewcontroller.swift
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 import UIKitclass GuideViewController:UIViewController,UIScrollViewDelegate{    var numOfPages = 3        override func viewDidLoad()    {        var frame = self.view.bounds        //scrollView的初始化        var scrollView=UIScrollView()        scrollView.frame=self.view.bounds        scrollView.delegate = self        //为了能让内容横向滚动,设置横向内容宽度为3个页面的宽度总和        scrollView.contentSize=CGSizeMake(frame.size.width*CGFloat(numOfPages),frame.size.height)        println("\(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{            var imgfile = "jianjie\(Int(i+1)).png"            println(imgfile)            var image = UIImage(named:"\(imgfile)")            var 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!)    {        println("scrolled:\(scrollView.contentOffset)")        var twidth = CGFloat(numOfPages-1) * self.view.bounds.size.width        if(scrollView.contentOffset.x > twidth)        {            var mainStoryboard = UIStoryboard(name:"Main", bundle:nil)            var viewController = mainStoryboard.instantiateInitialViewController() as UIViewController                        self.presentViewController(viewController, animated: true, completion:nil)        }    }}

Previous Swift-Setup app icon and launch screen

Swift-Wizard page at startup (Novice boot) production

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.