首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >上边半透明的效果并且显示的是上一页的内容

上边半透明的效果并且显示的是上一页的内容

作者头像
用户1219438
发布2018-02-01 15:48:10
9710
发布2018-02-01 15:48:10
举报
文章被收录于专栏:AliceAlice

项目介绍:首先上边显示的是透明的视图,透明度为0.8

这是一个vc 设置vc的view的背景颜色为clearcolor  上边是一个按钮,设置按钮的透明度为0.8 背景为黑色 

下边是一个btn 用来做点击事件。

代码附上:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    [btn setTitle:@"点击打开透明页" forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor  redColor];
    [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
}
-(void)btnClicked:(UIButton*)sender{
    NSLog(@"你点击了btn");
    
    //nextvc
    UIViewController *nextVC = [[UIViewController alloc]init];
    nextVC.view.backgroundColor = [UIColor clearColor];
    
    //设置上边的半透明的背景view
    UIButton *bgBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
    bgBtn.backgroundColor = [UIColor  blackColor];
    //设置形态的方式
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
        nextVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    }else{
        nextVC.modalPresentationStyle = UIModalPresentationCurrentContext;
    }
    bgBtn.alpha = 0.8;
    //天机点击事件 用来验证可点击
    [bgBtn addTarget:self action:@selector(btnClicked2:) forControlEvents:UIControlEventTouchUpInside];
    [nextVC.view addSubview:bgBtn];

    //分享的按钮的设置
    UIButton *shareBtn = [[UIButton alloc]initWithFrame:CGRectMake(50, 350, 50, 50)];
    [nextVC.view addSubview:shareBtn];
    shareBtn.backgroundColor  = [UIColor purpleColor];
    [shareBtn setTitle:@"tittle1" forState:UIControlStateNormal];
    [shareBtn addTarget:self action:@selector(tittleClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [self presentViewController:nextVC animated:YES completion:nil];
    
}
-(void)tittleClicked:(UIButton *)sender
{
    NSLog(@"你点击了第一个tittle");
}
-(void)btnClicked2:(UIButton*)sender
{
    NSLog(@"点击的是next的bgBtn");
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-07-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档