swift3.0 创建一个app引导页面
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引导页面的更多相关文章
- 如何为scratch3.0创建一个独立的页面或窗体
很多人都利用GIT上的scratch3.0做开发,但是苦于有些定制需要个性化开发但是不知道如何动手.本篇文章来做好普及工作吧. 首先需要完成事项如下: 1.需要进行modal定义 2.新增窗口的UI界 ...
- diango创建一个app
创建一个app terminal里执行命令 python manage.py startapp app名称 注册 settings配置 INSTALLED_APPS = [ 'app01', 'app ...
- 用weexplus从0到1写一个app(2)-页面跳转和文章列表及文章详情的编写
说明 结束连续几天的加班,最近的项目终于告一段落,今天抽点时间开始继续写我这篇拖了很久的<用weexplus从0到1写一个app>系列文章.写这篇文章的时候,weexplus的作者已经把w ...
- App引导页面源代码的实现
一.页面效果图
- react用脚手架创建一个react单页面项目,react起手式
官网地址:https://react.docschina.org/ 确保本地安装了Node.js node的版本大于8.10 npm的版本大于5.6 1.在本地的某个位置创建一个文件夹,执行以下 ...
- 001_创建一个sidebar切换页面
Table Of Content 准备 基本思路 实现 我们期望实现这样的效果: .listen(app.get('port'), function( ...
随机推荐
- 【总结】matlab求两个序列的相关性
首先说说自相关和互相关的概念. 自相关 在统计学中的定义,自相关函数就是将一个有序的随机变量系列与其自身作比较.每个不存在相位差的系列,都与其都与其自身相似,即在此情况下,自相关函数值最大. 在信号 ...
- 收集一些有用的docker镜像
https://hub.docker.com/explore/ 是star排名靠前的image =================================================== ...
- sql语句executeQuery和executeUpdate之间的区别
方法一.executeQuery 用于产生单个结果集(ResultSet)的语句,例如 SELECT 语句. 被使用最多的执行 SQL 语句的方法.这个方法被用来执行 SELECT 语句,它几乎是使用 ...
- mysql之高可靠
6.mysql主-从备份 主-主备份,首先AB机要保持数据一致,即先手工备份A机数据,然后在B机上恢复,之后就很简单了,只需要在B机上创建一个同步账号,并在A机上输入B机的那些参数然后启动slave ...
- Mysql 安装-操作-备份
Mysql 5.7 安装windows 1.配置mysql的path->系统属性->环境变量-path添加最后 2.配置目录和主从 [mysqld]port = 3306 basedir= ...
- asp.net gridview 鼠标悬浮提示信息
使用场景: gridview绑定数据,某列数据太多,故超过一定字符,隐藏起来,同时鼠标移到指定列显示其明细信息: 知识点: 1,oderListTbl_DataBound事件中,添加,oderList ...
- Jeesite的cahche工具类
本CacheUtils主要是基于shiro的cache进行处理. 其他选择: 类似的我们可以选择java cache ,spring cahche等方案. 再进一步 ...
- 搭建sonar,推动代码质量管理
最近比较关注devops相关的文章,尝试搭建sonarqube服务,进行代码质量的分析和管理,先记录下本地环境的搭建和分析过程. 一.sonarqube服务搭建 官网地址:http://www.son ...
- Mysql 客户端查询结果如何保存到本地而不是服务端?
应用场景:知道某台DB服务器的IP和账户,登录上去查询了10W条记录,需要把这些记录拉到本地做分析 方法1,远程连接到DB服务器执行OUTFILE命令,文件存储在DB机器上,只有mysql账户的情况下 ...
- log4net 配置
1.是直接在代码中通过调用XmlConfigurator.Configure()来解析配置文件,配置日志环境. log4net.Config.XmlConfigurator.Configure(); ...