【实践】图层控制,AB切换

来源:互联网 发布:java rest api 编辑:程序博客网 时间:2024/04/29 12:06

在self.view,上建立2个满屏幕的view,A和B

A上面再添加正常状态下的视图,B中添加弹出后的视图,可以把B的背景设为半透明

//切换,



- (void)viewDidLoad {

    [superviewDidLoad];

    

//弹出视图view2,可以添加很多东西

    _view2=[[UIViewalloc]initWithFrame:CGRectMake(0,0,self.view.bounds.size.width , self.view.bounds.size.height-20)];

    _view2.backgroundColor=[UIColorcolorWithRed:0green:0blue:0alpha:0.6];


    UIButton*button=[[UIButtonalloc]initWithFrame:CGRectMake(111,111, 111, 111)];

    button.backgroundColor=[UIColororangeColor];

    [button addTarget:selfaction:@selector(goto2)forControlEvents:UIControlEventTouchUpInside];

    [_view2addSubview:button];


//手势,点击Vie2,隐藏弹出视图

    UITapGestureRecognizer*tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(yc)];

    tap.cancelsTouchesInView =NO;

    _view2.userInteractionEnabled=YES;

    [_view2addGestureRecognizer:tap];

 

    [self.viewsendSubviewToBack:_view2];

    [self.viewaddSubview:_view2];

    


    

//view1是正常的显示界面,优先展示放下面

    

    _view1=[[UIViewalloc]initWithFrame:CGRectMake(0,0, self.view.bounds.size.width,self.view.bounds.size.height-20)];

    _view1.backgroundColor=[UIColorredColor];

   UIButton*button1=[[UIButtonalloc]initWithFrame:CGRectMake(100,100, 100, 30)];

    [button1 setTitle:@"弹出视图来"forState:UIControlStateNormal];

    [button1 addTarget:selfaction:@selector(tc)forControlEvents:UIControlEventTouchUpInside];

    button1.backgroundColor=[UIColorblackColor];

    [_view1addSubview:button1];

    [self.viewaddSubview:_view1];

    

}


-(void)tc

{

    [self.viewbringSubviewToFront:_view2];

}


-(void)yc

{

    [self.viewsendSubviewToBack:_view2];

}

-(void)goto2

{

    SBDLViewController*VIEW=[[SBDLViewControlleralloc]init];

    [self.navigationControllerpushViewController:VIEW animated:YES];    

}




0 0
原创粉丝点击