繁体   English   中英

iOS:如何从子视图中删除叠加层?

[英]iOS: How to remove overlay from it's subview?

我有按钮,使用标签和X按钮覆盖:

- (IBAction)taptaxi:(id)sender {
    UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    overlay.backgroundColor = [UIColor colorWithWhite:0 alpha:.7];
    UILabel *waiting = [[[UILabel alloc] initWithFrame:CGRectMake(50, 210, 250, 30)] autorelease];
    waiting.text = @"Waiting for cab response...";
    waiting.textColor = [UIColor whiteColor];
    waiting.backgroundColor = [UIColor clearColor];   
    waiting.font = [UIFont systemFontOfSize:14];

    UIButton *stoprequest = [[UIButton alloc] initWithFrame:CGRectMake(225, 219, 13, 13)];
    UIImage *srbackground = [[UIImage imageNamed:@"iks.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
    [stoprequest setBackgroundImage:srbackground forState:UIControlStateNormal];
    [stoprequest addTarget: self action: @selector(stopRequestMethod:) forControlEvents: UIControlEventTouchUpInside];

    [self.view.window addSubview:overlay];
    [overlay addSubview:waiting];
    [overlay addSubview:stoprequest];


}

- (void)stopRequestMethod: (id)sender
{
}

问题是 ,当我点击X butoon(stopRequestMethod)时,如何用标签和按钮隐藏/删除叠加?

为您的叠加层添加标签:

overlay.tag = 42;

然后,在按下X按钮时调用的方法中:

UIView *overlay = [self.view.window viewWithTag:42];
[overlay removeFromSuperview];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM