[英]Remove UIView From UIWindow
I have a UIViewController
whose view is added to my UIWindow
. 我有一个UIViewController
其视图被添加到我的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. @dasblinkenlight给了我这个想法,如果他回复我会给他答案。
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. setNeedsLayout
是关键,但我在窗口而不是adController的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]
如果您的构建目标是iOS 5.0+,我认为您应该考虑使用[viewController1 addChildViewController:viewController2]
May try this : 可以试试这个:
-(void)fullScreenAdViewControllerDidDismissAd(MobclixFullScreenAdViewController*)fullScreenAdViewController
{
NSLog(@"Dismissed");
[fullScreenAdViewController.view removeFromSuperview];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.