近期在玩"秘密",发现点击主界面的Cell进去后的页面效果不错,就写了个Demo来演示下.

它主要效果:下拉头部视图放大,上拉视图模糊并且到一定位置固定不动,其它Cell能够继续上移.

@封装的主要效果类:MTHeadEffect.m(.h文件省略,非常easy的)

#import "MTHeadEffect.h"
#import <QuartzCore/QuartzCore.h>
#import <Accelerate/Accelerate.h> // 屏幕的物理宽度
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define HeadViewH 40 CGFloat const kImageOriginHight = 200.f; @implementation MTHeadEffect + (void)viewDidScroll:(UIScrollView *)tableView withHeadView:(UIImageView *)headView withBlur:(CGFloat)blur{ NSLog(@"y = %f",tableView.contentOffset.y);
if (tableView.contentOffset.y > kImageOriginHight - HeadViewH) { headView.frame = CGRectMake(0, -(kImageOriginHight - HeadViewH), ScreenWidth, kImageOriginHight);
[[UIApplication sharedApplication].keyWindow addSubview:headView]; }else if ((tableView.contentOffset.y < kImageOriginHight - HeadViewH) && tableView.contentOffset.y > 0){ blur = (tableView.contentOffset.y) / 500.0 + 0.45;
headView.image = [[UIImage imageNamed:@"2"] boxblurImageWithBlur:blur];
headView.frame = CGRectMake(0, 0, ScreenWidth, kImageOriginHight);
[tableView addSubview:headView]; }else if (tableView.contentOffset.y <= 0){ // 放大效果---x,y坐标的增量和宽度,高度的增量保持一致
CGFloat offset = -tableView.contentOffset.y;
headView.frame = CGRectMake(-offset,-offset, ScreenWidth+ offset * 2, kImageOriginHight + offset);
headView.image = [[UIImage imageNamed:@"2"] boxblurImageWithBlur:0.01];
} } @end @implementation UIImage (BlurEffect) // 为高斯模糊效果封装的一个类目
-(UIImage *)boxblurImageWithBlur:(CGFloat)blur { NSData *imageData = UIImageJPEGRepresentation(self, 1); // convert to jpeg
UIImage* destImage = [UIImage imageWithData:imageData]; if (blur < 0.f || blur > 1.f) {
blur = 0.5f;
}
int boxSize = (int)(blur * 40);
boxSize = boxSize - (boxSize % 2) + 1; CGImageRef img = destImage.CGImage; vImage_Buffer inBuffer, outBuffer; vImage_Error error; void *pixelBuffer; //create vImage_Buffer with data from CGImageRef CGDataProviderRef inProvider = CGImageGetDataProvider(img);
CFDataRef inBitmapData = CGDataProviderCopyData(inProvider); inBuffer.width = CGImageGetWidth(img);
inBuffer.height = CGImageGetHeight(img);
inBuffer.rowBytes = CGImageGetBytesPerRow(img); inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData); //create vImage_Buffer for output pixelBuffer = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img)); if(pixelBuffer == NULL)
NSLog(@"No pixelbuffer"); outBuffer.data = pixelBuffer;
outBuffer.width = CGImageGetWidth(img);
outBuffer.height = CGImageGetHeight(img);
outBuffer.rowBytes = CGImageGetBytesPerRow(img); // Create a third buffer for intermediate processing
void *pixelBuffer2 = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img));
vImage_Buffer outBuffer2;
outBuffer2.data = pixelBuffer2;
outBuffer2.width = CGImageGetWidth(img);
outBuffer2.height = CGImageGetHeight(img);
outBuffer2.rowBytes = CGImageGetBytesPerRow(img); //perform convolution
error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer2, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
if (error) {
NSLog(@"error from convolution %ld", error);
}
error = vImageBoxConvolve_ARGB8888(&outBuffer2, &inBuffer, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
if (error) {
NSLog(@"error from convolution %ld", error);
}
error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
if (error) {
NSLog(@"error from convolution %ld", error);
} CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(outBuffer.data,
outBuffer.width,
outBuffer.height,
8,
outBuffer.rowBytes,
colorSpace,
(CGBitmapInfo)kCGImageAlphaNoneSkipLast);
CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
UIImage *returnImage = [UIImage imageWithCGImage:imageRef]; //clean up
CGContextRelease(ctx);
CGColorSpaceRelease(colorSpace); free(pixelBuffer);
free(pixelBuffer2);
CFRelease(inBitmapData); CGImageRelease(imageRef); return returnImage;
} @end

@main.m

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// tableView
self.testTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 568) style:UITableViewStylePlain];
self.testTableView.delegate = self;
self.testTableView.dataSource = self;
[self.view addSubview:_testTableView]; /**
* 隐藏状态栏效果
* 1.系统提供了2种动画,一种是偏移,一种是渐隐
* 2.在plist文件里将”View controller-based status bar appearance” 设置为 “No”
*/
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; // headView不作为tableHeadView,而是覆盖在第一个Cell上
self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
self.headView.image = [[UIImage imageNamed:@"2"] boxblurImageWithBlur:0.01];
self.headView.contentMode = UIViewContentModeScaleAspectFill; // 图片展示全高度
self.headView.clipsToBounds = YES;
[self.testTableView addSubview:self.headView]; } #pragma mark - scroll delegate 头部视图效果方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{ [MTHeadEffect viewDidScroll:scrollView withHeadView:self.headView withBlur:0.01];
} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 25;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row == 0) {
return 200;
}
return 40; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentf = @"cell";
UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellIdentf];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentf];
}
cell.textLabel.text = [NSString stringWithFormat:@"section = %ld row = %ld",indexPath.section,indexPath.row];
return cell; }

@效果图:额,不会制作gif动图,所以不太好演示,反正关键代码已经给出,大家能够自己去尝试.

@第三方FXBlurView做法的关键代码:

- (void)createBlurView{

    self.blurView = [[FXBlurView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, kOriginHight)];
self.blurView.tintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
self.blurView.blurRadius = 1.0;
self.blurView.dynamic = YES;
self.blurView.alpha = 0.0;
self.blurView.contentMode = UIViewContentModeBottom; } #pragma mark - scroll delegate 头部视图效果方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{ if (scrollView.contentOffset.y > 0) { self.blurView.alpha = 1.0;
self.blurView.blurRadius = scrollView.contentOffset.y / 4.0;
}
if (scrollView.contentOffset.y == 0) {
self.blurView.alpha = 0.0;
}
if (scrollView.contentOffset.y < 0) { CGFloat offset = - scrollView.contentOffset.y;
self.blurView.alpha = 0.0;
NSArray *indexPathArray = [self.testTableView indexPathsForVisibleRows];
HMTBlurTableViewCell *blurCell = (HMTBlurTableViewCell *)[self.testTableView cellForRowAtIndexPath:[indexPathArray objectAtIndex:0]];
blurCell.blurImageView.frame = CGRectMake(-offset, -offset, ScreenWidth + offset * 2, kOriginHight + offset); }
}

iOS开发之剖析&quot;秘密&quot;App内容页面效果(一)的更多相关文章

  1. iOS开发分析&quot;秘密&quot;App内容页面的效果(两)

    @我前几天写的"秘密"的Cell制品的效果,想要的效果还是有差距,并且扩展性非常不好,于是重写封装,把总体视图都放到scrollView中,基本是和secret app 一模一样的 ...

  2. 【转】 iOS开发之打包上传到App Store——(一)各种证书的理解

    OK,有日子没写iOS开发的相关文章啦,主要是最近的精力都没在这上面,不过既然产品已经快要出来了,就有必要了解一下各种证书啥的(众所周知iOS的一堆证书可是很让人头大呀),最近确实被这个搞得头大,然后 ...

  3. 《iOS开发实战 从入门到上架App Store(第2版)》书籍目录

    第1章 开发准备 1.1 iOS 10新特性简述 1.1.1 新增触觉反馈编程接口 1.1.2 SiriKit框架的开放 1.1.3 引入Messages App 1.1.4 通知框架的整合与扩展 1 ...

  4. iOS开发之企业发布无线安装APP

    前提是注册成为企业开发者(¥299),申请到证书并安装到本地,可以正常使用Xcode在IOS移动设备上进行Debug. 首先build看是否报错.如无错 执行下一: 执行Product—Archive ...

  5. iOS开发无第三方控件的援助达到的效果侧边栏

    最近的研究iOS程序侧边栏.渐渐的发现iOS该方案还开始采取风侧边栏格该,QQ,今日头条,Path(Path运营商最早的侧边栏app该,效果说成是Path效果),所以就研究了下. 然后发现Git Hu ...

  6. iOS - 开发一套代码多个app展示不同图标和名称

    引言 公司项目重构之后,有了相对比较完善的开发体系,首先git分支分为日常.预发.生产三个主要分支,开发阶段都在日常(daily)分支下开相应功能的feature分支,开发完再合并. 我的iOS工程需 ...

  7. iOS开发(1):设置APP的图标与启动图 | iOS图标的尺寸 | LaunchScreen的使用

    每个APP都应该有自己的图标跟启动图. 这里介绍怎么设置iOS的APP的图标跟启动图. (1)图标 小程的xcode是10.0版本,设置图标的入口如下: 点击入口后,进到设置页面,如下: 可以看到有很 ...

  8. iOS开发 点击跳转到App Store 或者 点击按钮去评价

    //跳转到应用页面 NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%d" ...

  9. iOS开发上架之itunes connect里app信息的编辑

    sku用于我们在后台识别自己的app,所以随你怎么填写

随机推荐

  1. (求助)对某一颜色,设置透明度 alpha 后,其他使用该颜色的地方 受到影响!!!!原因未知

    对某一颜色,设置透明度 alpha 后,其他使用该颜色的地方 受到影响!!!!原因未知,有谁碰到过这样的问题?????? 测试了以下三款手机,结果如下: 1.android 4.4.2: 不受影响 2 ...

  2. 使用QTP录制自带Flight小实例

    1.双击打开QTP10.0,启动过程中测试类型选择“WEB”. 2.进入主界面,New——Test,新建一个测试用例. 3.点击Record按钮,Record and settings对话框中,可以选 ...

  3. js文件中引用其他js文件

    这一个功能的作用是做自己的js包时,可以通过引入一个整体的js文件而引入其他js. 只需要在总体的js加上这一句话 document.write("<script type='text ...

  4. php经典bug

    <?php $tem = 0=="a"?1:2; echo $tem; ?> 输出结果为:1 原因:在0=="a",这个比较中因为会将字符串&quo ...

  5. CMD命令行提示被禁用的情况下如何继续使用命令行工具执行命令

    1.直接在Windows搜索 左下 输入要执行的 CMD 命令单句.多句同时执行没有试出来. 暂时记录这一条.2016-12-20

  6. (转)淘淘商城系列——导入商品数据到索引库——Service层

    http://blog.csdn.net/yerenyuan_pku/article/details/72894187 通过上文的学习,我相信大家已经学会了如何使用Solrj来操作索引库.本文我们将把 ...

  7. 安卓app测试之cpu监控

    安卓app测试之cpu监控,如何获取监控的cpu数据呢? 一.通过Dumpsys 来取值 1.adb shell dumpsys cpuinfo 二.top 1.top -d 1|grep packa ...

  8. 13Oracle Database 存储过程

    Oracle Database 存储过程 触发器相当于java中的事件监听,当某事件发生时激活特定的事件并执行相应的逻辑 DML触发器中包含了三种事件 insert update delete 语法格 ...

  9. (转)Oracle数据库DBA必备基本技能

    [Oracle数据库DBA必备基本技能] shutdown Normal 需要等待所有的用户断开连接 Immediate 等待用户完成当前的语句 Transactional    等待用户完成当前的事 ...

  10. HTTP服务和APACHE2

    HTTP服务和APACHE2 知识点 请求报文响应报文 错误码 请求重定向 编译安装 实现https curl工具 1. http协议 http协议版本 http/0.9, http/1.0, htt ...