iOS开发中怎么实现点击关闭按钮隐藏subView
1个回答
推荐于2018-03-21 · 知道合伙人影视综艺行家
关注
展开全部
iPhone应用中,添加subView到窗口,还要实现一个功能,在点击关闭按钮是,应该subView隐藏起来,这是创建subView的代码:
1
2
3
4
5
6
UIView*subView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 1024,768)];
subView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgPopupback.png"]];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:subView];
关闭按钮:
-(void)closeButtonAction{
NSLog(@"CLicked on this button");
[subView removeFromSuperview] ;
self.tableView.userInteractionEnabled=TRUE;
}
解决方法 1:
使用removefromsuperview删除subView,如果只是想隐藏 subView.hidden = YES;,在按钮动作内执行。
1
2
3
4
5
6
UIView*subView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 1024,768)];
subView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgPopupback.png"]];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:subView];
关闭按钮:
-(void)closeButtonAction{
NSLog(@"CLicked on this button");
[subView removeFromSuperview] ;
self.tableView.userInteractionEnabled=TRUE;
}
解决方法 1:
使用removefromsuperview删除subView,如果只是想隐藏 subView.hidden = YES;,在按钮动作内执行。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询