简体   繁体   中英

Remove UIView From UIWindow

I have a UIViewController whose view is added to my UIWindow . However, if I remove the view, I cannot tap anything below where it was. My code is below:

-(void)createFullAd{
    UIViewController *viewController = [UIViewController new];
    self.fullAd = [MobclixFullScreenAdViewController new];
    self.fullAd.delegate = self;
    [self.fullAd requestAndDisplayAdFromViewController:viewController];
    viewController.view.tag = 999999;
    [[[[UIApplication sharedApplication] delegate]window] addSubview:viewController.view];
}

- (void)fullScreenAdViewControllerDidDismissAd:(MobclixFullScreenAdViewController*)fullScreenAdViewController{
    NSLog(@"Dismissed");
    [[[[[UIApplication sharedApplication] delegate] window] viewWithTag:999999]removeFromSuperview];

}

@dasblinkenlight gave me the idea for this, if he posts back I will award the answer to him.

This is messy but it is the only thing that has worked:

-(void)displayAd {
    self.fullAd = [MobclixFullScreenAdViewController new];
    self.fullAd.delegate = self;
    self.adController = [UIViewController new];
    [self.fullAd requestAndDisplayAdFromViewController:self.adController];
    [[[[UIApplication sharedApplication] delegate]window] addSubview:self.adController.view];
}
- (void)fullScreenAdViewControllerDidDismissAd:(MobclixFullScreenAdViewController*)fullScreenAdViewController{
    [fullScreenAdViewController.view removeFromSuperview];
    [[[[UIApplication sharedApplication] delegate]window] setNeedsLayout];
    self.adController = nil;

}

setNeedsLayout is the key, but I called it on the window instead of the adController's superview.

I think this is just not the correct view hierarchy. If your building target is iOS 5.0+, I think you should consider using [viewController1 addChildViewController:viewController2]

May try this :

-(void)fullScreenAdViewControllerDidDismissAd(MobclixFullScreenAdViewController*)fullScreenAdViewController
{
    NSLog(@"Dismissed");
    [fullScreenAdViewController.view removeFromSuperview];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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