如何present出一个透明导航控制器NavigationController + UIVisualEffectView实现模糊效果、毛玻璃效果


在实际需求中使用模糊效果一般是: 原有界面(保持不变)+ 毛玻璃效果 + 需要展示的界面(上方)。


即:



1.新建工程 ,设置ViewController的背景图(淘宝首页截图),添加按钮及其事件

- (void)viewDidLoad {
    
    [super viewDidLoad];

    _imageView.frame = [UIScreen mainScreen].bounds;

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor orangeColor];
    btn.frame = CGRectMake(10, SCREEN_HEIGHT_NEW - 60, SCREEN_WIDTH_NEW - 10 * 2, 40);
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:@"点击展示模糊" forState:UIControlStateNormal];
    
}

- (void)click:(UIButton*)btn{
    
    MyTopViewController *topVC = [[MyTopViewController alloc]init];
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:topVC];
    //present出一个透明导航控制器NavigationController
    navi.modalPresentationStyle = UIModalPresentationCustom;
    [self presentViewController:navi animated:YES completion:^{}];
        
}

2在MyTopViewController中添加毛玻璃效果

- (void)viewDidLoad {
    [super viewDidLoad];

    //只有透明才能看到下方界面
    self.view.backgroundColor = [UIColor clearColor];
    
    
    //实现模糊效果
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];

    visualEffectView.frame = self.view.bounds;

    visualEffectView.alpha = 0.88;

    [self.view addSubview:visualEffectView];
    

    
    UITextField *textFiled = [[UITextField alloc]initWithFrame:CGRectMake(20, 200, SCREEN_WIDTH_NEW - 20*2, 40)];
    [self.view addSubview:textFiled];
    textFiled.placeholder = @"请输入手机号";
    textFiled.tintColor = [UIColor purpleColor];;
    textFiled.layer.borderWidth = 1;
    textFiled.layer.borderColor = [UIColor purpleColor].CGColor;
    
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor orangeColor];
    btn.frame = CGRectMake(10, 170 + 100, SCREEN_WIDTH_NEW - 10 * 2, 50);
    [btn setTitle:@"下一步" forState:UIControlStateNormal];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    
    
}

-(void)click{
    UIViewController *vc = [[UIViewController alloc]init];
    vc.view.backgroundColor = [UIColor grayColor];
    [self.navigationController pushViewController:vc animated:YES];
}


下载地址:http://download.csdn.net/detail/qq_15509071/9826691

点击打开链接



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值