【发布时间】:2017-07-04 02:52:04
【问题描述】:
我正在尝试使用有效的 UIElements 构建一个简单的库。我想做的是,从一个类实例创建 UIViewController 对象,并使用 presentViewController 方法将新的 ViewController 推送到当前 VC 堆栈上。
我可以看到 UIElements 已经成功添加到堆栈上,但是 GestureRecognizer 和 UIButton 的目标不起作用。当我检查 ViewDebug 时,这些设置是 <NSNull null>。
这是我创建 UI 并将其放入当前视图堆栈的类方法。
-(void)displayAd{
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
NSData * imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:fullpageCampaign.mainImage]];
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
fullPageView = [[UIViewController alloc] init];
fullPageView.view.frame = CurrentVC.view.bounds;
fullPageView.view.backgroundColor = [UIColor redColor];
UIImageView *staticImageView = [[UIImageView alloc] init];
staticImageView.frame = CurrentVC.view.frame;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
singleTap.numberOfTapsRequired = 1;
[staticImageView addGestureRecognizer:singleTap];
staticImageView.userInteractionEnabled = YES;
[fullPageView.view addSubview:staticImageView];
staticImageView.image = [UIImage imageWithData:imageData];
[CurrentVC.view addSubview:fullPageView.view];
//[fullPageView didMoveToParentViewController:self];
[CurrentVC presentViewController:fullPageView animated:YES completion:^{
NSLog(@"Tagon Ads is about to showing.");
UIButton *closeButton = [self createButtonWithAssetName:@"tagonAssets.bundle/close_button" TargetMethod:@"closeModal" andView:staticImageView];
[staticImageView addSubview:closeButton];
[CurrentVC.view bringSubviewToFront:closeButton];
}];
});
});
}
CurrentVC 是我通过库的方法作为参数发送的当前 viewController,以便在其上添加新的 viewController 堆栈。
【问题讨论】:
-
你确定这个链接和我的问题有关吗?
-
尝试设置 CurrentVC.view.clipsToBounds = YES;如果您的 ui 元素消失,则意味着您设置 CurrentVC.view.frame 不正确
-
我的 UIElements 并没有消失,它们只是不能像 GestureRecognizer、UIButton target 和 @selectors 等一样设置 Target 和 UIEvents。
-
请问,如果您已经将 fullPageView 的视图添加为子视图,为什么还要在
CurrentVC上显示fullPageView?
标签: ios objective-c uiview uiviewcontroller