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 updated, and the following code is added to the Appdelegate.swift:
FuncApplication(Application:uiapplication, didfinishlaunchingwithoptions launchoptions: [Nsobject:anyobject]?) -Bool {Override point for customization after application launch.Get the version number of the current appLet infodictionary =Nsbundle.mainbundle (). infodictionaryLet currentappversion = infodictionary! ["Cfbundleshortversionstring"]AsStringLet Userdefaults =Nsuserdefaults.standarduserdefaults ()Let appversion = Userdefaults.stringforkey ( "appversion") var storyboard = uistoryboard (name: " Main ", Bundle: nil) //if AppVersion is nil description is the first time to start If appversion is not equal to Currentappversion description is updated if appversion = nil || AppVersion! = currentappversion {userdefaults.setvalue (currentappversion, Forkey: " AppVersion ") var Guidanceviewcontroller = Storyboard.instantiateviewcontrollerwithidentifier ( "GUIDANCEVC") as guidanceviewcontroller self.window!. Rootviewcontroller = Guidanceviewcontroller} return true}
In Guidanceviewcontroller, we use Uiscrollview to load our guide page.
ImportUIKitClassGuidanceviewcontroller:Uiviewcontroller {var ScrollView:uiscrollview!@IBOutletWeakvar Pagecontrol:uipagecontrol!@IBOutletWeakvar Startbutton:uibutton!var numofpages =4OverrideFuncViewdidload() {Super.viewdidload ()Do any additional setup after loading the view.var frame =Self.view.bounds ScrollView =Uiscrollview () Scrollview.frame =Self.view.bounds scrollview.delegate =SelfScrollView's contentsize is set to 4 of the screen width (I have set four guide pages here) times Scrollview.contentsize =Cgsizemake (Frame.size.width *CGFloat (numofpages), frame.size.height) scrollview.pagingenabled =True scrollview.showshorizontalscrollindicator =False scrollview.showsverticalscrollindicator =False scrollview.scrollstotop =FalseFor IInch0..<numofpages {var image =UIImage (named:"Guidance\ (i +1) ")var ImageView =Uiimageview (image:image) Imageview.frame =CGRectMake (Frame.size.width *CGFloat (i),0, Frame.size.width, frame.size.height) Scrollview.addsubview (imageView)} Scrollview.contentoffset =CgpointzeroSelf.view.addSubview (scrollView) Startbutton.alpha =0.0Get these two controls to the top of the viewSelf.view.bringSubviewToFront (Pagecontrol)Self.view.bringSubviewToFront (Startbutton)}OverrideFuncDidreceivememorywarning() {Super.didreceivememorywarning ()Dispose of any resources the can be recreated. } @IBAction func start (sender:anyobject) {var storyboard = uistoryboard (name: "Main", Bundle: nil) Span class= "Hljs-keyword" >var Viewcontroller = Storyboard.instantiateviewcontrollerwithidentifier (" LOGINVC ") as loginviewcontroller Viewcontroller.modaltransitionstyle = uimodaltransitionstyle. Crossdissolve Presentviewcontroller (Viewcontroller, animated: true, Completion: nil)}}
Finally we let Guidanceviewcontroller follow the Uiscrollviewdelegate protocol, here to decide whether to slide to the last one to show the Enter button.
MARK:-UiscrollviewdelegateExtensionGuidanceviewcontroller:uiscrollviewdelegate {func scrollviewdidscroll ( Scrollview:uiscrollview) {var 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.5) {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:
Effect Show
[IOS] Implementation of a simple App guide page (Swift)