Swift3 页面顶部实现拉伸效果代码
//懒加载
//顶部需要拉伸自定义视图
lazy var headView:MyHeaderView = {
//let hframe = CGRect(x: 0, y: 0, width: swidth, height: swidth/self.imgRation)
// let hview = Bundle.main.loadNibNamed("MyInfoHeaderView", owner: nil, options: nil)?.first as! MyInfoHeaderView
//return hview;
}() //MARK:1)集合视图
self.collectionView?.addSubview(self.headView)
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.section == 0 { //顶部返回一个空的cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
return cell
}
.... func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.section == 0 {//顶部
return CGSize(width: swidth, height:200.0 )
}
.... //MARK:2)列表视图
self.tableView?.addSubview(self.headView)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 { //顶部返回一个空的cell
var cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier)
return cell!
}
.... override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0{
return 200.0;
}
.... //MARK:拉伸效果实现位置
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let point = scrollView.contentOffset;
if point.y <= 0 {//下拉
//self.headView.frame.size.height = swidth/imgRation - point.y
//self.headView.frame.size.width = self.headView.frame.size.height*imgRation
//self.headView.frame.origin.x = (swidth - self.headView.frame.size.width)/2
//self.headView.frame.origin.y = point.y
//self.headView.titleImgLeft.constant = 18 - self.headView.frame.origin.x
//self.mainNavView.backgroundColor = UIColor.clear
//self.mainNavView.searImg.image = UIImage(named: "搜索框r")
}else{//上推
//if point.y >= (self.headView.frame.height - 64){
//self.mainNavView.searImg.image = UIImage(named: "搜索框w")
//self.mainNavView.searchText.backgroundColor = UIColor.white
//}
//self.headView.titleImgLeft.constant = 18
// self.mainNavView.backgroundColor = UIColor(red:245/255.0, green:74/255.0, blue:48/255.0, alpha: point.y/(self.headView.frame.height - 64))
}
}
Swift3 页面顶部实现拉伸效果代码的更多相关文章
- 回到顶部缓动效果代码 --- tween动画函数库
function animateGoTop() { var top = $(document).scrollTop(); var end = 0; var dur = 500; var t = 0; ...
- 用jquery实现小火箭到页面顶部的效果
恩,不知道之前在哪看过一个页面效果就是如果页面被滑动了就出现一个小火箭,点击这个小火箭就可以慢慢回到页面顶部,闲的没事,自己搞了一下 需要引入jquery 代码和布局都很简单 <!DOCTYPE ...
- 代码: 返回页面顶部 jquery
jquery代码: 返回页面顶部 <script type="text/javascript" src="http://cdn.bootcss.com/jquery ...
- 【jQuery】页面顶部显示的进度条效果
<!Doctype html> <html> <head> <title>页面顶部显示的进度条效果</title> <meta htt ...
- js网页返回页面顶部的小方法
咳咳,在网页出现滚动条的时候,许多网站会在右下角出现一个图标,点击可以回到页面顶部 本文就记录下js实现代码: 1.在html页面body添加dom元素 <img src="toTop ...
- HTML5商城开发五 实现返回页面顶部
本文内容主要是网上参考收集,介绍四种简单的返回页面顶部代码,可以使用简单的HTML锚标记,也可使用Javascript Scroll函数动态返回等等. 一.使用锚标记返回页面顶部 使用HTML锚标记最 ...
- marquee标签实现页面内容的滚动效果
页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...
- [JS,NodeJs]个人网站效果代码集合
上次发的个人网站效果代码集合: 代码集合: 1.彩色文字墙[鼠标涟漪痕迹] 2.彩色旋转圆环 [模仿http://www.moma.org/interactives/exhibitions/2012/ ...
- 解决点击a标签返回页面顶部的问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- POJ1659 Frogs' Neighborhood(青蛙的邻居) Havel-Hakimi定理
Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 8729 Accepted: 36 ...
- Netty 源码 Channel(一)概述
Netty 源码 Channel(一)概述 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) Channel 为 Netty ...
- nginx的hash
hash结构中有若干个桶,桶内是hash(key)值相同的若干数据. 查找数据时,首先对key值进行hash计算,然后hash值对桶的个数进行求余,得到数据所在的桶.然后在桶中使用key逐个查找,直到 ...
- SQL表两列取一列唯一值的记录
问下SQL表两列取一列唯一值的 A列 B列 C列 1001 AA 2012-01-02 1001 BB 2012-02-05 100 ...
- 如何在Android平台上使用USB Audio设备
http://blog.csdn.net/kevinx_xu/article/details/12951131 需求:USB Headset插上去后,声音要从本地CODEC切换到USB Headset ...
- Django之url定义和ORM框架的使用
前言,Django安装 pip install django # 官网安装最新版本 pip install django -i "https://pypi.doubanio.com/simp ...
- 【转】mysql 解事务锁
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction 原创 2014年07月31日 10:59:43 5 ...
- Hadoop3集群搭建之——安装hadoop,配置环境
接上篇:Hadoop3集群搭建之——虚拟机安装 下篇:Hadoop3集群搭建之——配置ntp服务 Hadoop3集群搭建之——hive安装 Hadoop3集群搭建之——hbase安装及简单操作 上篇已 ...
- c# 抽象类和抽象方法
参考:http://www.runoob.com/csharp/csharp-polymorphism.html https://zhidao.baidu.com/question/587686949 ...
- i2c设备驱动注册
Linux I2C设备驱动编写(二) 原创 2014年03月16日 23:26:50 在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_driver.i2c ...