项目来源翻译大神的swift 本版为objectc版本,
大神地址:
这里写链接内容

一.效果图如下:

没什么逻辑可讲述的,直接给源码吧:

//
//  ViewController.m
//  ZFBHome
//
//  Created by 刘xx on 2018/6/12.
//  Copyright © 2018 liuxx. All rights reserved.
//#import "ViewController.h"
#import "HeadView.h"#define SCREEN_HEIGHT                      [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTH                       [UIScreen mainScreen].bounds.size.width@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>@property (nonatomic) UIView *coverNavView;
@property (nonatomic) UIView *mainNavView;
@property (nonatomic) HeadView *headerView;@property (nonatomic) UITableView *tableView;@property (nonatomic) HeadView * childView;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];[self buildUI];}-(void) buildUI{self.coverNavView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 64)];self.coverNavView.alpha = 0;self.coverNavView.backgroundColor = [UIColor blueColor];[self.view addSubview:self.coverNavView];UIButton *scan_mini = [UIButton buttonWithType:UIButtonTypeCustom];scan_mini.frame = CGRectMake(10,(64 - 35) / 2,35,35);[scan_mini setImage:[UIImage imageNamed:@"pay_mini@2x"] forState:UIControlStateNormal];[self.coverNavView addSubview:scan_mini];UIButton *pay_mini = [UIButton buttonWithType:UIButtonTypeCustom];pay_mini.frame = CGRectMake(60,(64 - 35) / 2,35,35);[pay_mini setImage:[UIImage imageNamed:@"pay_mini@2x"] forState:UIControlStateNormal];[self.coverNavView addSubview:pay_mini];UIButton *add = [UIButton buttonWithType:UIButtonTypeCustom];add.frame = CGRectMake(SCREEN_WIDTH - 60,(64 - 35) / 2,35,35);[add setImage:[UIImage imageNamed:@"pay_mini@2x"] forState:UIControlStateNormal];[self.coverNavView addSubview:add];self.mainNavView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 64)];self.mainNavView.backgroundColor = [UIColor blueColor];[self.view addSubview:self.mainNavView];UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 8, 322, 44)];searchBar.text = @"游戏";[self.mainNavView addSubview:searchBar];UIButton *contact = [UIButton buttonWithType:UIButtonTypeCustom];contact.frame = CGRectMake(SCREEN_WIDTH - 60,(64 - 35) / 2,35,35);[contact setImage:[UIImage imageNamed:@"home_contacts@2x"] forState:UIControlStateNormal];[self.mainNavView addSubview:contact];//构建导航与菜单栏self.childView = [[HeadView alloc] init];//构建滚动列表self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 84, SCREEN_WIDTH, SCREEN_HEIGHT - 84) style: UITableViewStylePlain];self.tableView.delegate = self;self.tableView.dataSource = self;self.headerView = self.childView;self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 305);[self.tableView addSubview:self.headerView];self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 305)];self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(305, 0, 0, 0);[self.view addSubview:self.tableView];}- (void)viewDidLayoutSubviews{[super viewDidLayoutSubviews];self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 305);
}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 15;
}static NSString* cellID = @"cellID";- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell* tableViewCell = [tableView dequeueReusableCellWithIdentifier:cellID];if (tableViewCell == nil) {tableViewCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];}tableViewCell.textLabel.text = @"test";return tableViewCell;
}//实现滚动UIScrollViewDelegate 协议
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{CGFloat offsetY = scrollView.contentOffset.y;if(offsetY > 0 && offsetY < 24){[self.tableView setContentOffset:CGPointMake(0, 0) animated:true];}else if(offsetY >= 24 && offsetY < 95){[self.tableView setContentOffset:CGPointMake(0, 95) animated:true];}
}- (void)scrollViewDidScroll:(UIScrollView *)scrollView{CGFloat offsetY = scrollView.contentOffset.y;if(offsetY <= 0){self.headerView.frame = CGRectMake(0, offsetY, SCREEN_WIDTH, 305);[self.childView changAlpha:1];self.coverNavView.alpha = 0;self.mainNavView.alpha = 1;}else if(offsetY > 0 && offsetY < 95){CGFloat alpha = (1 - offsetY / 95) > 0 ? (1 - offsetY / 95) : 0;[self.childView changAlpha:alpha / 3];if(alpha > 0.9){self.coverNavView.alpha = 0;self.mainNavView.alpha = alpha / 5;}else{self.mainNavView.alpha = 0;self.coverNavView.alpha = 1 - alpha;if(alpha <= 0.75){[self.childView changAlpha:0];}}}}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];}@end

headView.h:

//
//  HeadView.h
//  ZFBHome
//
//  Created by 刘小兵 on 2018/6/12.
//  Copyright © 2018 liuxx. All rights reserved.
//  头部视图 主要包括 可变化导航视图的与 网格菜单视图#import <UIKit/UIKit.h>@interface HeadView : UIView<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>@property(nonatomic,strong) UIView* headTopView;
@property(nonatomic,strong) UICollectionView* menuView;-(void) changAlpha:(CGFloat) alpha;@end

headView.m

//
//  HeadView.m
//  ZFBHome
//
//  Created by 刘小兵 on 2018/6/12.
//  Copyright © 2018 liuxx. All rights reserved.
//#import "HeadView.h"
#import "UIButton+ImgLabel.h"#define SCREEN_HEIGHT                      [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTH                       [UIScreen mainScreen].bounds.size.width@implementation HeadView-(instancetype) initWithFrame:(CGRect)frame{if(self = [super initWithFrame:frame]){[self initView];}return self;
}-(void) initView{NSLog(@"26-----------");//构建头部视图容器self.headTopView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 95)];self.headTopView.backgroundColor = [UIColor cyanColor];[self addSubview:self.headTopView];UIButton* scanBtn = [UIButton buttonWithType:UIButtonTypeCustom];scanBtn.frame = CGRectMake(10, 7.5, 100, 80);scanBtn.backgroundColor = [UIColor redColor];[scanBtn setImage:[UIImage imageNamed:@"home_scan@2x"] forState:UIControlStateNormal];[scanBtn setTitle:@"scan" forState:UIControlStateNormal];[scanBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];[scanBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleBottom imageTitleSpace:10];[self.headTopView addSubview:scanBtn];//1.初始化layoutUICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];self.menuView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 95, SCREEN_WIDTH, 240) collectionViewLayout:layout];self.menuView.dataSource = self;self.menuView.delegate = self;self.menuView.backgroundColor = [UIColor whiteColor];[self.menuView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collectionCell"];[self addSubview:self.menuView];}-(void) changAlpha:(CGFloat)alpha{self.headTopView.alpha = alpha;
}//实现协议方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{return 1;
}- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{return 12;
}- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];cell.backgroundColor = [UIColor cyanColor];return cell;
}- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{CGFloat width = (SCREEN_WIDTH - 100) / 4;return CGSizeMake(width, 50);
}- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{return 20;
}- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{return UIEdgeInsetsMake(10, 15, 10, 15);}@end

IOS仿支付宝首页滑动效果相关推荐

  1. 仿path首页滑动效果

    最近在研究path的首页滑动效果,发现啪啪也已经实现了这个效果,自己网上找了代码,又自己试试,发现如果是用两个ImageView 做的话,可以实现,但是用listView的话,滑动就会出问题,现在把代 ...

  2. 使用html仿支付宝首页,iOS 仿支付宝首页样式(二)

    那篇文章里面方法有个一弊端,就是UITableView的高度和Cell的总高度一致,也就是UITableView不能滑动,UITableViewCell的复用机制页就不起作用了.哈哈,懒人版的支付宝首 ...

  3. iOS 仿支付宝首页样式

    效果图: 了解一下他们的层级关系,还是先看图,方便解释: 图片已经标明的很明白,我们在控制器先放上一个UIScrollView,在它的上面分别放上一个HeaderView(UIView)和一个UITa ...

  4. 高仿支付宝首页头部动画

    高仿支付宝首页头部动画(使用design实现效果,CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+Toolbar) 效果图(效果图渐变不明 ...

  5. iOS 仿支付宝密码支付

    代码地址如下: http://www.demodashi.com/demo/11484.html 一.准备工作 xcode 主要实现输入密码的时候不可见 二.程序实现 实现思路怎样 在支付宝输入密码的 ...

  6. android+qq底部界面,Android 高仿QQ 界面滑动效果

    Android高仿QQ界面滑动效果 点击或者滑动切换画面,用ViewPager实现, 首先是布局文件: android:layout_width="match_parent" an ...

  7. 仿支付宝蚂蚁森林效果

    CustomWaterView 项目地址:xiaohaibin/CustomWaterView  简介::star: 仿支付宝蚂蚁森林效果 更多:作者   提 Bug 标签: 实现原理文章:https ...

  8. 仿支付宝首页应用管理(拖拽排序,添加删除)

    MenuManage-Imitate-Alipay 项目地址:ywanhzy/MenuManage-Imitate-Alipay  简介:仿支付宝首页应用管理(拖拽排序,添加删除) 更多:作者   提 ...

  9. 仿支付宝首页顶部滑动效果

    最近开发有一个需求 仿照支付宝首页顶部滑动的特效,由于之前没写过,既然这次有这个需求,那我们就来好好的研究一下 实现这个的需求 我们就需要了解一个新的布局 android.support.design ...

最新文章

  1. Python使用matplotlib可视化绘制并通过Tkinter生成按钮将可视化结果导出为pdf文件
  2. Qt 汽车仪表再次编写,Widget,仪表显示,绘制界面
  3. HTTP/2笔记之连接建立
  4. [转]VS2010安装说明及所有安装出错的解决办法
  5. 图解linux下top命令的使用
  6. boost库shared_ptr实现桥接模式
  7. Spring Boot + Shiro 集成
  8. mysql版本 hibernate_Mysql 不同版本 说明
  9. 计算机科学申请文书,美国留学:看牛人怎么写申请计算机CS专业的文书
  10. 死磕Android_App 启动过程(含 Activity 启动过程)
  11. 信息图表是如何炼成的(二):图标与线条
  12. c32-野指针和内存操作分析
  13. Java单例模式的双if
  14. 计网实验(一):IP子网划分
  15. 男生种草潮流社区edge(嘿市),会是男生的小红书吗?
  16. P4556 [Vani有约会]雨天的尾巴 树链剖分 线段树合并
  17. 为什么宇宙年龄138亿年(哈勃常数的倒数),大小竟有930亿光年?
  18. 北京清大美博节能技术研究院励志人生格言
  19. 微信小程序报错unshift is not a function
  20. 苹果6s最大屏幕尺寸_iPhone12来了,我决定给老苹果升级一下电池

热门文章

  1. 实现1V1音视频实时互动直播系统 十二、第三节 直播系统中的信令及其逻辑关系
  2. 【小结】南京大学软件工程专硕2021二战小结
  3. F4键无法在Excel里正常使用
  4. 周末两天入门 PCB 设计
  5. php 直接显示缩略图,PHP自动生成缩略图函数的源码示例
  6. 数据结构算法之子集树
  7. jTessBoxEditor2.3.1训练字库
  8. 不管是否情愿,5G要来了,运营商该做的事一样也不能少
  9. 2022危险化学品经营单位安全管理人员考试试题及答案
  10. 零代码极限封装的【接口自动化测试框架】震碎你的三观