我一直在寻找一种解决方案,即在输入背景时不捕获缓存中的屏幕截图。我发现我可以通过调用UIImageView
中的AppDelegate
来捕获我的屏幕而不是自定义图像。
- (void)applicationDidEnterBackground:(UIApplication *)application {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
imageView.tag = 101;
imageView.backgroundColor = [UIColor blackColor];
[UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
UIImageView *imageView = (UIImageView *)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101];
[imageView removeFromSuperview];
}
我的应用程序在一段时间后注销用户,显示用户已注销并返回主视图的错误。但是现在当应用程序在后台注销时,它不会在返回应用时删除UIImageView
。我该如何删除UIImageView
?
答案 0 :(得分:0)
用强大的指针握住你的imageView!
@property (strong, nonatomic) UIImageView *imageView;
//...
- (void)applicationDidEnterBackground:(UIApplication *)application {
self.imageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
self.imageView.backgroundColor = [UIColor blackColor];
[UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
[self.imageView removeFromSuperview];
}