UIBlurEffect - 模糊效果

2020-05-07  本文已影响0人  js_huh

是什么?

有什么用?

怎么使用?

有什么特点?

示例

- (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];
}

效果图

效果图

UIBlurEffectStyle - 模糊效果样式

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

猜你喜欢

热点阅读