1

我有 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;

  }
4

4 回答 4

9

您可以删除您的subView使用removeFromSuperview,如果您只想隐藏您的子视图,则意味着subView.hidden = YES;在您的按钮操作中使用

于 2013-07-18T05:17:23.050 回答
3

删除您的视图

[yourView removeFromSuperview];  

隐藏您的视图

[yourView setHidden:YES];
于 2013-07-18T05:12:03.353 回答
1

如果您只是想隐藏您的子视图,那么在您的 -(void)closeButtonAction 方法中这样做

-(void)closeButtonAction{



   NSLog(@"CLicked on this button");

  //[subView removeFromSuperview] ; 

  subView.alpha = 0;

  self.tableView.userInteractionEnabled=TRUE;

  }
于 2013-07-18T06:26:08.963 回答
0
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];

    }
于 2013-07-18T05:15:49.893 回答