iOS开发之剖析"秘密"App内容页面效果(一)
近期在玩"秘密",发现点击主界面的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开发之剖析"秘密"App内容页面效果(一)的更多相关文章
- iOS开发分析"秘密"App内容页面的效果(两)
@我前几天写的"秘密"的Cell制品的效果,想要的效果还是有差距,并且扩展性非常不好,于是重写封装,把总体视图都放到scrollView中,基本是和secret app 一模一样的 ...
- 【转】 iOS开发之打包上传到App Store——(一)各种证书的理解
OK,有日子没写iOS开发的相关文章啦,主要是最近的精力都没在这上面,不过既然产品已经快要出来了,就有必要了解一下各种证书啥的(众所周知iOS的一堆证书可是很让人头大呀),最近确实被这个搞得头大,然后 ...
- 《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 ...
- iOS开发之企业发布无线安装APP
前提是注册成为企业开发者(¥299),申请到证书并安装到本地,可以正常使用Xcode在IOS移动设备上进行Debug. 首先build看是否报错.如无错 执行下一: 执行Product—Archive ...
- iOS开发无第三方控件的援助达到的效果侧边栏
最近的研究iOS程序侧边栏.渐渐的发现iOS该方案还开始采取风侧边栏格该,QQ,今日头条,Path(Path运营商最早的侧边栏app该,效果说成是Path效果),所以就研究了下. 然后发现Git Hu ...
- iOS - 开发一套代码多个app展示不同图标和名称
引言 公司项目重构之后,有了相对比较完善的开发体系,首先git分支分为日常.预发.生产三个主要分支,开发阶段都在日常(daily)分支下开相应功能的feature分支,开发完再合并. 我的iOS工程需 ...
- iOS开发(1):设置APP的图标与启动图 | iOS图标的尺寸 | LaunchScreen的使用
每个APP都应该有自己的图标跟启动图. 这里介绍怎么设置iOS的APP的图标跟启动图. (1)图标 小程的xcode是10.0版本,设置图标的入口如下: 点击入口后,进到设置页面,如下: 可以看到有很 ...
- iOS开发 点击跳转到App Store 或者 点击按钮去评价
//跳转到应用页面 NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%d" ...
- iOS开发上架之itunes connect里app信息的编辑
sku用于我们在后台识别自己的app,所以随你怎么填写
随机推荐
- python 正则表达式操作
正则表达式操作 本模块提供了类似于Perl的正则表达式匹配操作.要匹配的模式和字符串可以是Unicode字符串以及8位字符串. 正则表达式使用反斜杠字符('\')来表示特殊的形式或者来允许使用特殊的 ...
- win7 中使用NFS共享
转自和修改自:http://blog.sina.com.cn/s/blog_553761ef0100oevm.html 一 安装 在卸载或更改程序->打开或关闭windows的功能-> 安 ...
- DVWA--登录页面错误问题 469 | | PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\web\DVWA\dvwa\includes\dvwaPage.inc.php:469
// MySQL PDO Prepared Statements (for impossible levels) $db = new PDO('mysql:host=' . $_DVWA[ 'db_s ...
- POJ_1163_The triangle
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 40079 Accepted: 24144 De ...
- jmeter插件之PerfMon
PerfMon是jmeter监控系统资源的一款插件,可以用来监控系统的CPU/内存/IO等性能指标. 一.要准备好的插件:JMeterPlugins-Standard-1.4.0(pwd:cjqd)或 ...
- Flask框架 之第一个Flask程序
from flask import Flask # 创建flask应用对象 # __name__ 代表当前模块名称 # flask以当前目录为总目录,static目录为静态目录,templates为模 ...
- JavaScipt30(第一个案例)(主要知识点:键盘事件以及transitionend)
今天得到一个github练习项目,是30个原生js写成的小例子,麻雀虽小五脏俱全,现在记录一下第一个. 第一个是键盘按键时页面上对应的键高亮,同时播放音频,松开后不再高亮. 我自己实现了一下,然后查看 ...
- php file_get_contents函数分段读取大记事本或其它文本文件
当我们遇到文本文件体积很大时,比如超过几十M甚至几百M几G的大文件,用记事本或者其它编辑器打开往往不能成功,因为他们都需要把文件内容全部放到内存里面,这时就会发生内存溢出而打开错误,遇到这种情况我们可 ...
- 第三节:执行一些EF的增删改查
针对两表操作 一丶增加 #region 05-增加操作 /// <summary> /// 05-增加操作 /// </summary> /// <param name= ...
- 【原】Mysql存储关联数组
$fruits= array("apple" => "苹果", "banana" => "香蕉"," ...