iOS-毛玻璃、navigationBar滑动颜色渐变
1、毛玻璃实现
iOS8以上,官方提供了系统方法实现毛玻璃,代码如下:
// iOS8 UIVisualEffectView
UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"car.png"]];
bgView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:bgView];
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
blurView.alpha = 0.9; // 控制模糊程度
blurView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[bgView addSubview:blurView];
UIVibrancyEffect *vibrancyView = [UIVibrancyEffect effectForBlurEffect:(UIBlurEffect *)blurView.effect];
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:vibrancyView];
visualEffectView.translatesAutoresizingMaskIntoConstraints = NO;
[blurView.contentView addSubview:visualEffectView];
a> UIBlurEffectStyle = UIBlurEffectStyleExtraLight;

b> UIBlurEffectStyle = UIBlurEffectStyleLight;

c> UIBlurEffectStyle = UIBlurEffectStyleDark;

2、导航栏滑动渐变
导航栏最开始的状态是透明的状态,可以看到后面的图片。之后随着用户的滑动颜色开始加深。
代码如下:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
}
在tableview或scrollview的代理方法中:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat minAlphaOffset_Y = - 64;
CGFloat maxAlphaOffset_Y = 125;
CGFloat offset_Y = scrollView.contentOffset.y;
CGFloat alpha = (offset_Y - minAlphaOffset_Y) / (maxAlphaOffset_Y - minAlphaOffset_Y);
[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:alpha];
}
但是在跳转的时候需要恢复原状,即导航栏呈现不透明状态,可以封装跳转方法:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:1];
[self.navigationController pushViewController:viewController animated:animated];
}
iOS-毛玻璃、navigationBar滑动颜色渐变的更多相关文章
- iOS 动画绘制线条颜色渐变的折线图
效果图 .................... 概述 现状 折线图的应用比较广泛,为了增强用户体验,很多应用中都嵌入了折线图.折线图可以更加直观的表示数据的变化.网络上有很多绘制折线图的demo,有 ...
- ios显示艺术字字体颜色渐变
UIColor * myColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"123.jpg"]]; self. ...
- iOS开发之创建颜色渐变视图View
在iOS开发中有时需要自己自定义一个视图view的背景,而网上有人提出的在循环中不断alloc的方法设置其背景色渐变,会耗费很多内存和资源,极其不明智,而在CALayer中早就提供有图层渐变的类和相应 ...
- 【iOS开发系列】颜色渐变
记录: //Transparent Gradient Layer - (void) insertTransparentGradient { UIColor *colorOne = [UIColor c ...
- IOS导航栏颜色渐变与常用属性
(转:http://www.cnblogs.com/Lingchen-start/archive/2015/10/23/4904361.html) 今年很忙,忙的写日志的时间都很少. 少的可怜. 自 ...
- IOS之UI--动态设置NavigationBar的颜色以及透明度
前言:有时候我们需要设置UINavigationController的导航条NavigationBar的颜色为透明度,这时候就需要使用到NavigationBar的barStyle这个属性: 再看QQ ...
- WPF 背景颜色渐变的滑动条实现
原文:WPF 背景颜色渐变的滑动条实现 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/details/83507 ...
- 【iOS实现一个颜色渐变的弧形进度条】
在Github上看到一些进度条的功能,都是通过Core Graph来实现.无所谓正确与否,但是开发效率明显就差很多了,而且运行效率还是值得考究的.其实使用苹果提供的Core Animation能够非常 ...
- iOS 之使用CAShapeLayer中的CAGradientLayer实现圆环的颜色渐变
本文转载自:http://blog.csdn.net/zhoutao198712/article/details/20864143 在 Github上看到一些进度条的功能,都是通过Core Graph ...
随机推荐
- 【Todo】Nodejs学习计划
/Users/baidu/Documents/Data/Interview/Web-Server开发/深入浅出Node.js-f46c.pdf /Users/baidu/Documents/Data/ ...
- openstack学习笔记(一)-openstack的基础知识
一.OpenStack的基础知识 openstack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache2.0许可证(兼容GPLv3以及DFSG)授权的自由软件和 ...
- Kubernetes用户指南(二)--部署组合型的应用、连接应用到网络中
一.部署组合型的应用 1.使用配置文件启动replicas集合 k8s通过Replication Controller来创建和管理各个不同的重复容器集合(实际上是重复的pods). Replicati ...
- iOS小技巧 - 如何生成范围随机数
生成[0, N-1]的随机数 NSUInteger r = arc4random_uniform(N); 生成[1, N]的随机数 NSUInteger r = arc4random_uniform( ...
- 爪哇国新游记之二十八----从url指定的地址下载文件到本地
package download; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; ...
- Spring AOP实现拦截转发控制
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ...
- J2SE语言--百度百科
Java2平台包括:标准版(J2SE).企业版(J2EE)和微缩版 (J2ME)三个版本.J2SE,J2ME和J2EE,这也就是SunONE(Open NetEnvironment)体系.J2SE就是 ...
- C# Windows form application 播放小视频
1. 下载direcly-show lib DLL点击打开链接 2. DxPlay.cs (能够在下载的样例中找到): public class DxPlay : IDisposable { e ...
- 批量杀进程 ps awk grep
ps aux |grep lt-newindexclient |grep -v grep |awk grep -v 反向输出,即过滤掉带有grep的输出. xargs:传递参数
- Timus Online Judge 1057. Amount of Degrees(数位dp)
1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the am ...