美文网首页
UIVibrancyEffect - 活力效果

UIVibrancyEffect - 活力效果

作者: js_huh | 来源:发表于2020-05-07 11:25 被阅读0次

是什么?

  • UIVibrancyEffect 活力/鲜艳效果
  • -@interface UIVibrancyEffect : UIVisualEffect //继承自 UIVisualEffect

有什么用?

  • 放大和调整位于 视觉效果视图 后面内容的颜色.
  • 通常UIVibrancyEffect是和UIBlurEffect一起使用得,处理UIBlurEffect特效上的一些显示效果.
  • UIVisualEffectViewcontentView中的内容看起来更加生动.

怎么使用?

  • 为特效的"模糊效果",创建"鲜艳的效果".
    + (UIVibrancyEffect *)effectForBlurEffect:(UIBlurEffect *)blurEffect;
  • 创建具有指定"模糊效果""样式值""鲜艳效果".
    + (UIVibrancyEffect *)effectForBlurEffect:(UIBlurEffect *)blurEffect style:(UIVibrancyEffectStyle)style;

有什么特点?

  • UIVibrancyEffect做为一个子视图,放置在UIVisualEffectView的上面,去连接UIBlurEffect.
  • 这种效果只会影响添加到UIVisualEffectViewcontentView上的内容。
  • UIVibrancyEffect的鲜艳度效果取决于颜色
- (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];
        }
      

相关文章

网友评论

      本文标题:UIVibrancyEffect - 活力效果

      本文链接:https://www.haomeiwen.com/subject/jfzdwhtx.html