是什么?
-
UIVibrancyEffect
活力/鲜艳效果 -
-@interface UIVibrancyEffect : UIVisualEffect
//继承自 UIVisualEffect
有什么用?
- 放大和调整位于 视觉效果视图 后面内容的颜色.
- 通常
UIVibrancyEffect
是和UIBlurEffect
一起使用得,处理UIBlurEffect
特效上的一些显示效果. - 让
UIVisualEffectView
里contentView
中的内容看起来更加生动.
怎么使用?
- 为特效的"模糊效果",创建"鲜艳的效果".
+ (UIVibrancyEffect *)effectForBlurEffect:(UIBlurEffect *)blurEffect;
- 创建具有指定"模糊效果"和"样式值"的"鲜艳效果".
+ (UIVibrancyEffect *)effectForBlurEffect:(UIBlurEffect *)blurEffect style:(UIVibrancyEffectStyle)style;
有什么特点?
-
UIVibrancyEffect
做为一个子视图,放置在UIVisualEffectView
的上面,去连接UIBlurEffect
. - 这种效果只会影响添加到
UIVisualEffectView
的contentView
上的内容。 -
UIVibrancyEffect
的鲜艳度效果取决于颜色
![](https://img.haomeiwen.com/i2337348/9a2e8ca1ce9d375f.png)
- (void)viewDidLoad {
[super viewDidLoad];
CGRect screenRect = [[UIScreen mainScreen] bounds];
//模糊效果
UIBlurEffect * blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
//鲜艳效果
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];
//视觉效果视图
UIVisualEffectView * visualEffectView = [[UIVisualEffectView alloc]initWithEffect:vibrancyEffect];
//visualEffectView.backgroundColor = [ UIColor grayColor ];
[visualEffectView setFrame:screenRect];
//图片
UIImageView * imgView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"pic_14"]];
CGRect effViewFrame = CGRectMake(100, 300, 80, 80);
[imgView setFrame:effViewFrame];
[visualEffectView.contentView addSubview:imgView];
[self.view addSubview:visualEffectView];
}
示例:
-
lblText
没有设置字体颜色,它的颜色来源于背景图片.- 是通过
UIBlurEffect
将文字模糊化后,
通过UIVibrancyEffect
将背景图片的"鲜艳度进行了调整",
最后形成模糊化的背景颜色的字体颜色和文字.
- (void)viewDidLoad { [super viewDidLoad]; CGRect screenRect = [[UIScreen mainScreen] bounds]; self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pic_14"]]; //文本框设置 UILabel *lblText = [[UILabel alloc]initWithFrame:CGRectMake(80, 300, 280, 90)]; lblText.text = @"来时刻积分卡芙兰达框架类库"; lblText.textAlignment = NSTextAlignmentLeft; lblText.font = [UIFont systemFontOfSize:28]; lblText.numberOfLines = 0; //模糊效果 UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; //鲜艳效果 UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect]; //视觉效果视图 UIVisualEffectView * visualEffectView = [[UIVisualEffectView alloc]initWithEffect:vibrancyEffect]; [visualEffectView setFrame:screenRect]; //将文本框,添加到"视觉效果视图"的contentView上 [visualEffectView.contentView addSubview:lblText]; [self.view addSubview:visualEffectView]; }
- 是通过
网友评论