UIBlurEffect - 模糊效果

是什么?

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

有什么用?

  • 模糊效果应用在视觉效果视图 (UIVisualEffectView) 上.

怎么使用?

  • 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 - 模糊效果)