[IOS] Simple implementation of the app's Guide page (Swift 2)

Source: Internet
Author: User

Reprint Please specify source: http://www.jianshu.com/p/024dd2d6e6e6#

Updated to Xcode7.2, Swift2.1

Always use the Guide page to display product features after the first time you open an app or app update

We use the NSUserDefaults class to determine whether the program is first started or is updated, AppDelegate.swift adding the following code in:

FuncApplication(Application:uiapplication, didfinishlaunchingwithoptions launchoptions: [Nsobject:anyobject]?) -Bool {Get the version number of the current appLet infodictionary =Nsbundle.mainbundle (). infodictionaryLet currentappversion = infodictionary! ["Cfbundleshortversionstring"]as!StringRemove the previously saved version numberLet Userdefaults =Nsuserdefaults.standarduserdefaults ()Let appversion = Userdefaults.stringforkey ("AppVersion")let storyboard = uistoryboard (name:  " Main ", Bundle: nil) //if appversion is nil the description is the first time to start; if appversion Not equal to Currentappversion description is updated if appversion = nil | | appVersion! = currentappversion {//Save the latest version number Userdefaults.setvalue (Currentappversion, ForKey:  "appversion") let Guideviewcontroller = Storyboard.instantiateviewcontrollerwithidentifier ( "Guideviewcontroller") as! guideviewcontroller self.window?. Rootviewcontroller = Guideviewcontroller} return true} 

In GuideViewController , we use UIScrollView to load our guide page:

ClassGuideviewcontroller:Uiviewcontroller {@IBOutletWeakvar Pagecontrol:uipagecontrol!@IBOutletWeakvar Startbutton:uibutton! Privatevar ScrollView:uiscrollview! PrivateLet numofpages =3OverrideFuncViewdidload() {Super.viewdidload ()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 =CgpointzeroSet the contentsize of the ScrollView to 3 times times the screen width (depending on the actual situation) Scrollview.contentsize =Cgsize (Width:frame.size.width *CGFloat (numofpages), height:frame.size.height) Scrollview.delegate =SelfFor indexInch0..<numofpages {Notice the name of the picture hereLet ImageView =Uiimageview (Image:UIImage (named:"Guideimage\ (Index +1) ") Imageview.frame = cgrect (x:frame.size.width * cgfloat (index), y: 0, Width:frame.size.width, Height:frame.size.height) Scrollview.addsubview (ImageView)} self.view.insertsubview (ScrollView, Atindex: 0) //set fillet for Start button StartButton.layer.cornerRadius = 15.0 //hide Start button Startbutton.alpha = 0.0} //hidden status bar override  Func prefersstatusbarhidden ()  Bool {return true}}      

Finally, let's GuideViewController follow the UIScrollViewDelegate agreement here to determine whether to slide to the last one to show the Enter button:

MARK:-UiscrollviewdelegateExtensionGuideviewcontroller:uiscrollviewdelegate {func scrollviewdidscroll ( Scrollview:uiscrollview) {let offset = Scrollview.contentoffset //with sliding change pagecontrol status Pagecontrol.currentpage = Int (Offset.x/ View.bounds.width) //because CurrentPage is starting from 0, so numofpages minus 1 if Pagecontrol.currentpage = = numofpages-1 { Uiview.animatewithduration (0.5) {self.startButton.alpha = Span class= "Hljs-number" >1.0}} else { Uiview.animatewithduration (0.2) {self.startButton.alpha = Span class= "Hljs-number" >0.0}}}            

In the above code, in order to appear natural we have added a little animation to the Enter button:]

The final effect is as follows:


Guidescreenshot.gif

GitHub Address: Https://github.com/GuiminChu/JianshuExample



Wen/Leo (Jane book author)
Original link: http://www.jianshu.com/p/024dd2d6e6e6
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

[IOS] Simple implementation of the app's Guide page (Swift 2)

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.