开发者社区 问答 正文

关于点击关闭按钮隐藏subView 的问题

iPhone应用中,添加subView到窗口,还要实现一个功能,在点击关闭按钮是,应该subView隐藏起来,这是创建subView的代码:

 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;

}

展开
收起
爵霸 2016-03-17 15:14:07 2113 分享 版权
1 条回答
写回答
取消 提交回答
  • 使用removefromsuperview删除subView,如果只是想隐藏 subView.hidden = YES;,在按钮动作内执行。

    2019-07-17 19:05:29
    赞同 展开评论
问答分类:
问答地址: