当用户单击添加按钮时,我将在 UIWindow 上添加 View 。现在,如果用户再次点击添加按钮,我想先删除该 View 并再次添加。
我已使用此代码在 UIWindow 上添加 View :
ProgressVC *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"IDProgressVC"];
[[[[UIApplication sharedApplication] delegate]window] addSubview:vc.view];
对于删除,我已经尝试过此代码:
[vc.view removeFromSuperview];
[[[[UIApplication sharedApplication] delegate]window] setNeedsLayout];
vc = nil;
我们将不胜感激。
最佳答案
试试这个
// Make this global property
@property(nonatomic, strong) UIView * currentView;
//store the view in gloabal property
ProgressVC *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"IDProgressVC"];
currentView = vc.view;
[[[[UIApplication sharedApplication] delegate]window] addSubview:currentView];
//remove it
[currentView removeFromSuperview];
[[[[UIApplication sharedApplication] delegate]window] setNeedsLayout];
currentView = nil;
关于ios - 从 UIWindow 中移除 UIViewController 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38100956/