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( ...
随机推荐
- unity行为树制作AI简单例子(1)
用行为树来制作AI是非常方便的,今天就给大家简单介绍一下行为树的强大之处. 所用插件 Behavior Designer v1.421 最开始 我使用过Rain插件,不过用过Behavior Desi ...
- [转]Linux命令的返回值
Linux命令的返回值 对于某些监测脚本和探测命令蛮有用的: 在 Linux 下,不管你是启动一个桌面程序也好,还是在控制台下运行命令,所有的程序在结束时,都会返回一个数字值,这个值叫做返回值,或者称 ...
- OpenStack Mitaka安装
http://egon09.blog.51cto.com/9161406/1839667 前言: openstack的部署非常简单,简单的前提建立在扎实的理论功底,本人一直觉得,玩技术一定是理论指导实 ...
- (转) Awesome Deep Learning
Awesome Deep Learning Table of Contents Free Online Books Courses Videos and Lectures Papers Tutori ...
- CentOS以及Oracle数据库发展历史及各版本新功能介绍, 便于构造环境时有个对应关系
CentOS版本历史 版本 CentOS版本号有两个部分,一个主要版本和一个次要版本,主要和次要版本号分别对应于RHEL的主要版本与更新包,CentOS采取从RHEL的源代码包来构建.例如CentOS ...
- Oracle虚拟索引,大表或生产环境下预估索引效果的好东西
在数据库优化过程中,索引的重要性是不言而喻的,但是在我们进行性能调整过程中, 一个索引是否能够被使用到,在索引创建之前是存在不确定性的. 而创建索引又是一个代价很高的操作,尤其是数据量很大的情况下,在 ...
- RegOpenKeyEx和RegSetValueEx返回ERROR_SUCCESS,但注册表未发生变化。
win7 x64,需要open的时候加上KEY_WOW64_64KEY. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microso ...
- [转]Windows进程间通信的各种方法
http://www.cnblogs.com/songQQ/archive/2009/06/03/1495764.html 道相似,不过它传输数据是通过不可靠的数据报(如TCP/IP协议中的UDP包) ...
- Nim Game,Reverse String,Sum of Two Integers
下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...
- Best Practices for Background Jobs_3 Managing Device Awake State之电源锁、Alarm、WakefulBroadcastReceiver
http://developer.android.com/training/scheduling/index.html 当静置一个设备的时候,先会屏幕变暗,然后关闭屏幕,最后关闭CPU,以省电.但有的 ...