u010025993
shrimp-hamburger
采纳率81.1%
2013-07-18 07:02 阅读 2.1k
已采纳

点击关闭按钮隐藏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;

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    Kill_it Kill_it 2013-07-18 08:40

    使用removefromsuperview删除subView,如果只是想隐藏 subView.hidden = YES;,在按钮动作内执行。

    点赞 评论 复制链接分享
  • xinyoulingxi1_tong xinyoulingxi1_tong 2013-07-18 08:36
    viewDidLoad()
    {
    UIButton *m_btnSample = [UIButton buttonWithType:UIButtonTypeCustom];
        [m_btnSample setFrame:CGRectMake(200, 300, 200, 40)];
        [m_btnSample setImage:[UIImage imageNamed:@"smiley1.jpg"] forState:UIControlStateNormal];
        [m_btnSample addTarget:self action:@selector(btnChanged) forControlEvents:UIControlStateHighlighted];
        [self.view addSubview:m_btnSample];
    }
    
     -(void)btnChanged
        {
            [viewYouWantToRemove removeFromSuperview];
    
        }
    
    点赞 评论 复制链接分享

相关推荐