美文网首页
UIBlurEffect - 模糊效果

UIBlurEffect - 模糊效果

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

是什么?

  • UIBlurEffect 模糊效果
  • @interface UIBlurEffect : UIVisualEffect, 继承自 UIVisualEffect

有什么用?

怎么使用?

  • UIBlurEffect * blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

有什么特点?

  • "用指定样式UIBlurEffectStyle,创建模糊效果."
    + (UIBlurEffect *)effectWithStyle:(UIBlurEffectStyle)style;

示例

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    UIImageView * imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pic_14"]];
    [imgView setFrame:screenRect];

    //模糊效果
    UIBlurEffect *blurEffrct =[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    //视觉效果视图
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffrct];
    visualEffectView.frame = CGRectMake(100, 300, 80, 80);
    
    //imgView包含了visualEffectView.
    [imgView addSubview:visualEffectView];
    [self.view addSubview:imgView];
    
    // imgView 和 visualEffectView 是两个独立体
    //[self.view addSubview:imgView];
    //[self.view addSubview:visualEffectView];
}

效果图

效果图
  • [imageView addSubview:visualEffectView]; //视觉效果视图包含在imageView里面.

  • [self.view addSubview:visualEffectView];//视觉效果视图imageView是分别独立得.


UIBlurEffectStyle - 模糊效果样式

   typedef enum (NSInteger, UIBlurEffectStyle) {
    UIBlurEffectStyleExtraLight, //高亮风格
    UIBlurEffectStyleLight, // 亮风格
    UIBlurEffectStyleDark, // 暗风格
    UIBlurEffectStyleExtraDark, // 超暗风格
    UIBlurEffectStyleRegular, 
    UIBlurEffectStyleProminent,
} NS_ENUM_AVAILABLE_IOS(8_0);

相关文章

网友评论

      本文标题:UIBlurEffect - 模糊效果

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