swift毕竟不像是oc ,第三方的框架很多,更何况是3.0,自己动手写了个引导页面,看得上我代码的麻友可以拿去用

引导页面有三个部分构成,scrollview用语切换引导视图,pageControll用语指示引导页的页码,点击进入按钮引导用户进入app;

class LRFirstIntroduceController: UIViewController, UIScrollViewDelegate {

    let numPages  = 3
var pageControl = UIPageControl()
var beginBtn = UIButton()
let pageControlWidth = 60 override func viewDidLoad() {
super.viewDidLoad()
let frame = self.view.bounds let scrollView = UIScrollView.init()
scrollView.frame = frame
scrollView.delegate = self //为了能让内容横向移动 设置横向宽度为3个页面的宽度之和
scrollView.contentSize = CGSize.init(width:KJRScreenWidth * CGFloat(numPages) , height: KJRScreenHeight)
scrollView.isPagingEnabled = true
scrollView.showsHorizontalScrollIndicator = false
scrollView.showsVerticalScrollIndicator = false

//        scrollsToTop是UIScrollView的一个属性,主要用于点击设备的状态栏时,是scrollsToTop == YES的控件滚动返回至顶部。

//        每一个默认的UIScrollView的实例,他的scrollsToTop属性默认为YES,所以要实现某一UIScrollView的实例点击设备状态栏返回顶部,则需要关闭其他的UIScrollView的实例的scrollsToTop属性为NO。很好理解:若多个scrollView响应返回顶部的事件,系统就不知道到底要将那个scrollView返回顶部了,因此也就不做任何操作了。。。

        scrollView.scrollsToTop = false
scrollView.bounces = false for index in 0..<numPages {
let imageView = UIImageView.init(image: UIImage.init(named: "GuideImage\(index + 1).png"))
imageView.frame = CGRect.init(x: KJRScreenWidth * CGFloat(index), y: 0, width: KJRScreenWidth, height: KJRScreenHeight)
scrollView.addSubview(imageView)
} self.view.addSubview(scrollView) let pageControlx = KJRScreenWidth - CGFloat(pageControlWidth) pageControl = UIPageControl.init(frame: .init(x: pageControlx/2, y: KJRScreenHeight - 50.0, width:CGFloat(pageControlWidth) , height: 20)) pageControl.numberOfPages = numPages pageControl.currentPage = 0 view.addSubview(pageControl) beginBtn = UIButton.init(type: .custom)
beginBtn.backgroundColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
beginBtn.frame = CGRect.init(x: pageControlx/2, y: KJRScreenHeight - 80, width:CGFloat(pageControlWidth), height: 25)
beginBtn.setTitle("点击进入", for: .normal)
beginBtn.titleLabel?.adjustsFontSizeToFitWidth = true
beginBtn.layer.masksToBounds = true
beginBtn.layer.cornerRadius = 3.0
view.addSubview(beginBtn)
beginBtn.alpha = 0.0 self.view.bringSubview(toFront: pageControl)
self.view.bringSubview(toFront: beginBtn) } func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset
// 随着滑动改变pageControl的状态
pageControl.currentPage = Int(offset.x / view.bounds.width)
// 因为currentPage是从0开始,所以numOfPages减1
if pageControl.currentPage == numPages - 1 {
UIView.animate(withDuration: 0.5) {
self.beginBtn.alpha = 0.8
}
} else {
UIView.animate(withDuration: 0.5) {
self.beginBtn.alpha = 0.0
}
}
}

  

swift3.0 创建一个app引导页面的更多相关文章

  1. 如何为scratch3.0创建一个独立的页面或窗体

    很多人都利用GIT上的scratch3.0做开发,但是苦于有些定制需要个性化开发但是不知道如何动手.本篇文章来做好普及工作吧. 首先需要完成事项如下: 1.需要进行modal定义 2.新增窗口的UI界 ...

  2. diango创建一个app

    创建一个app terminal里执行命令 python manage.py startapp app名称 注册 settings配置 INSTALLED_APPS = [ 'app01', 'app ...

  3. 用weexplus从0到1写一个app(2)-页面跳转和文章列表及文章详情的编写

    说明 结束连续几天的加班,最近的项目终于告一段落,今天抽点时间开始继续写我这篇拖了很久的<用weexplus从0到1写一个app>系列文章.写这篇文章的时候,weexplus的作者已经把w ...

  4. App引导页面源代码的实现

    一.页面效果图

  5. react用脚手架创建一个react单页面项目,react起手式

    官网地址:https://react.docschina.org/ 确保本地安装了Node.js node的版本大于8.10    npm的版本大于5.6 1.在本地的某个位置创建一个文件夹,执行以下 ...

  6. 001_创建一个sidebar切换页面

    Table Of Content 准备 基本思路 实现 我们期望实现这样的效果: ![](https://img2018.cnblogs.com/blog/1735896/202001/1735896 ...

  7. 【原创】使用.NET Core 1.0创建一个Self-Contained控制台应用

    开发机器:win7-x64 .NET Core版本:1.0.0-preview2-003121 Visual Studio Code:1.2.1 至于什么是Self-Contained应用类型以及与P ...

  8. 前端实现app引导页面动画效果

    插件描述:jQuery引导插件TourTip 交互式可视化指南网页上的元素.使用方法 步骤1: 将以下标记添加到您的文档的<head> 你还需要复制旁边插件的css文件夹和下载的IMG文件 ...

  9. nodejs express 框架解密2-如何创建一个app

    本文是基于express 3.4.6 的 1.在我们的app.js 文件里面有这么几行 http.createServer(app).listen(app.get('port'), function( ...

随机推荐

  1. div四个边框分别设置阴影样式

    对于div边框的阴影一直没有很好地理解,也一直不明白怎么给四个边框分别设置阴影.昨天项目中碰到了这个问题,就认真想了一下,在此总结一二. 首先,还是从官方解释说起. 网上的解释通常都是什么水平阴影长度 ...

  2. Saying that Java is nice because it works on every OS is like saying that anal sex is nice because it works on every gender.

    Saying that Java is nice because it works on every OS is like saying that anal sex is nice because i ...

  3. javascript生成对象的三种方法

    /** js生成对象的三种方法*/ // 1.通过new Object,然后添加属性 示例如下: var people1 = new Object(); people1.name = 'xiaohai ...

  4. (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about t

    运行redis过程中,突然报错如下: (error) MISCONF Redis is configured to save RDB snapshots, but is currently not a ...

  5. 在.htaccess文件中写RewriteRule无效的问题的解决

    近来在Apache Rewrite 拟静态配置时,遇到个问题.写的如下: RewriteEngine onRewriteRule ^/t_(.*)/$ /test.php?id=$1 保存在httpd ...

  6. Codeforces Round #377 (Div. 2) D. Exams(二分答案)

    D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...

  7. js转换数据类型为浮点型,并取两位小数点

    转换数据类型 parseFloat();//转换为浮点型 parseInt();//转换为整形 取后面两位小数 bianliang.toFixed(2);//取后面两位小数,2代表取多少位

  8. 一次Redis的使用Bug记录(exec)

    博主在一次项目中,使用了工具类中的Redis类,因为该Redis没有封装管道pipeline和exec命令,所以就大笔一挥来了一段__call; 代码如下(其中$this->_connect() ...

  9. Linux添加主机路由

    Linux添加主机路由:参考:http://zhidao.baidu.com/link?url=50qQ232ZiJqq1iftHvBdPzZh-JlQGi1DZ8wvF-j9dvQYsKiNgc-6 ...

  10. 对话框AlertDialog.Builder使用方法

    我们在平时做开发的时候,免不了会用到各种各样的对话框,相信有过其他平台开发经验的朋友都会知道,大部分的平台都只提供了几个最简单的实现,如果我们想实现自己特定需求的对话框,大家可能首先会想到,通过继承等 ...