Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Swift - 启动时的向导页(新手引导)的制作大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

在很多iOS产品或者一些应用版本的升级中,新手指导(引导页面)都是一个常用的功能,通过说明页的左右滑动,可以很清晰的展示系统的一些功能特性。制作思路如下: 1,如何检测应用是第一次登陆启动 我们可以使用NSUserDefaults类来解决这个问题。其特点是不会因应用的关闭、系统的重启而丢失。所以可以用来标记是否启动过。 2,新手引导视图控制器我们使用UIScrollView 比如我们设置了一套新手
在很多iOS产品或者一些应用版本的升级中,新手指导(引导页面)都是一个常用的功能,通过说明页的左右滑动,可以很清晰的展示系统的一些功能特性。制作思路如下:

1,如何检测应用是第一次登陆启动
我们可以使用NSUserDefaults类来解决这个问题。其特点是不会因应用的关闭、系统的重启而丢失。所以可以用来标记是否启动过。

2,新手引导视图控制器我们使用UIScrollView
比如我们设置了一套新手引导图共三张,都添加到UIScrollView里,这时UIScrollView的内容宽度是3倍于照片或者屏幕的宽度。

3,为适应不同分辨率,需要设计几套不同尺寸的图
iOS图片资源的命名规则是: basename + screen size modifier + urischeR_237_11845@e + orientation + scale + device + .ext
basename文件
screen size modifier:屏幕尺寸修饰符(iPhone5出现后才有,如 -568h)
urischeR_237_11845@e:标识URI方案的字符串(一般情况不需要关心)
orientation:屏幕方向(横屏为-Landscape,竖屏为-PorTrait)
scale:缩放尺寸(普通屏不需要,ReTina屏为@2x,iPhone6后多了个@3x)
device:设备类型(~ipad表示供iPad使用)
.ext:文件扩展名(可以是png或其他格式)
尽管文件很复杂,但调用却很简单,只要写上basename.ext即可。

4,效果图如下:
5,文件结构如下:
6,入口类:AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
@H_618_122@ 11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import UIKit
@UIApplicationMain
class AppDelegate : UIResponder , UIApplicationDelegate {
@H_262_203@ var window: UIWindow ?
func application(application: UIApplication :1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
didFinishLaunchingWithOptions launchOptions: [ NSObject : AnyObject ]?) -> Bool {
// Override point for customization after application launch.
//增加标识,用于判断是否是第一次启动应用...
if (!( NSUserDefaults .standardUserDefaults().boolForKey( "everLaunched" ))) {
.standardUserDefaults().setBool( true :1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,forKey: )
guideViewController = GuideViewController ()
self .window!.rootViewController=guideViewController;
println ( "guideview launched!" )
}
return true
}
applicationWillResignActive(application: ) {
}
@H_262_302@
applicationDidEnterBACkground(application: ) {
}
applicationWillEnterForeground(application: ) {
}
applicationDidBecomeActive(application: ) {
}
applicationWillTerminate(application: ) {
}
}

7,向导页面:GuideViewController.swift
35
36
37
38
39
40
41
42
43
44
45
46
UIViewController UIScrollViewDelegate
@H_607_382@numOfPages = 3
@H_262_203@
@H_307_404@override viewDidLoad()
{
frame = .view.bounds
//scrollView的初始化
scrollView= UIScrollView ()
scrollView.frame= .view.bounds
scrollView.delegate = self
//为了能让内容横向滚动,设置横向内容宽度为3个页面的宽度总和
scrollView.contentSize= CGSizeMake (frame.size.width* CGFloat (numOfPages),frame.size.height)
"\(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{
imgfile = "jianjie\(Int(i+1)).png"
@H_262_302@(imgfilE)
image = UIImage (named: "\(imgfilE)" )
imgView = UIImageView (image: imagE)
imgView.frame= CGRectMake (i),monospace!important; min-height:inherit!important">(0),
frame.size.width,frame.size.height)
scrollView.addSubview(imgView)
}
scrollView.contentOffset = CGPointZero
.view.addSubview(scrollView)
}
scrollViewDidScroll(scrollView: !)
{
"scrolled:\(scrollView.contentOffset)" )
twidth = (numOfPages-1) * .view.bounds.size.width
(scrollView.contentOffset.x > twidth)
{
@H_801_513@mainStoryboard = UIStoryboard (name: "Main" :1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,bundle: nil )
viewController = mainStoryboard.instantiateInitialViewController() as UIViewController
.presentViewController(viewController,animated: :1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,completion: )
}
}
}

大佬总结

以上是大佬教程为你收集整理的Swift - 启动时的向导页(新手引导)的制作全部内容,希望文章能够帮你解决Swift - 启动时的向导页(新手引导)的制作所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:swift制作向导启动引导新手
猜你在找的Swift相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap