iOS系列UI篇——UIVisualEffectView

来源:互联网 发布:苹果接电话变声软件 编辑:程序博客网 时间:2024/05/22 14:22

这是一个iOS 8.0才出来的效果——毛玻璃~现在很多APP都已经在用了,从用户体验这个角度来说,确实更能直接的吸收到用户眼球!功能比较简单,直接上代码

#import "ViewController.h"#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height@interface ViewController (){    UIBlurEffect * _eff;    UIVisualEffectView * _vev;}@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    //创建一个背景图片    UIImageView * imageView = [[UIImageView alloc] initWithFrame:(CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))];    [imageView setImage:[UIImage imageNamed:@"1"]];    [self.view addSubview:imageView];        //设置效果style    /*     UIBlurEffectStyleExtraLight, 高亮     UIBlurEffectStyleLight, 一般     UIBlurEffectStyleDark 暗     */    _eff = [UIBlurEffect effectWithStyle:(UIBlurEffectStyleLight)];        //在UIVisualEffectView加上这个效果    _vev = [[UIVisualEffectView alloc] initWithEffect:_eff];    _vev.frame =  CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 2);    [self.view addSubview:_vev];        UIButton * button = [[UIButton alloc] initWithFrame:(CGRectMake((_vev.frame.size.width - 50)/2, (_vev.frame.size.height - 50) / 2, 50, 50))];    button.backgroundColor = [UIColor redColor];    button.alpha = 0.3;    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:(UIControlEventTouchUpInside)];    [_vev addSubview:button];}- (void)buttonClicked:(UIButton *)sender{    //改变透明度    if (_vev.alpha >= 0.1f) {        _vev.alpha -= 0.01f;    }}


0 0
原创粉丝点击