从另一个子视图中删除模糊视图

时间:2015-10-04 14:22:34

标签: ios objective-c subview

我在视图中添加了2个子视图( EOPSessionsViewController ), blurEffectView reLogInView

    if (!UIAccessibilityIsReduceTransparencyEnabled()) {
        self.view.backgroundColor = [UIColor clearColor];

        UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
        UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
        blurEffectView.tag = 123;
        blurEffectView.frame = self.view.bounds;
        blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

        [self.view addSubview:blurEffectView];
    }else{
        self.view.backgroundColor = [UIColor blackColor];
    }

    self.reLogInView = [[ReLoginViewController alloc]initWithNibName:@"ReLoginViewController" bundle:nil];

    [self.view addSubview:self.reLogInView.view];
    self.reLogInView.view.frame = CGRectMake(0, 0, self.view.frame.size.width/2, self.view.frame.size.height/2);
    self.reLogInView.view.center = self.view.center;
    self.reLogInView.view.backgroundColor = [UIColor grayColor];
    self.reLogInView.view.layer.borderColor = [UIColor blackColor].CGColor;
    self.reLogInView.view.layer.borderWidth = 3.0f;

当用户点击 reLogInView 中的取消按钮时,我想删除 blurEffectView reLogInView 。截至目前,我可以使用下面的代码删除 reLogInView

- (IBAction)cancel:(id)sender {

    [self.view removeFromSuperview];

}

我的问题是如何同时删除 blurEffectView ?请注意,其中3个是不同的类。

1 个答案:

答案 0 :(得分:1)

尝试添加以下内容:

self.reLogInView.sessionsVC = self;

在第一个代码段中。 (声明如下):

@interface ReLoginViewController : (???) <???>
...
@property (strong) EOPSessionsViewController *sessionsVC;

然后:

- (IBAction)cancel:(id)sender {
    [self.view removeFromSuperview];
    [self.sessionsVC.blurEffectView removeFromSuperview];
}