当用户通过将应用程序切换到前台来激活应用程序时,我需要在屏幕上隐藏某些内容。
我已尝试在applicationDidBecomeActive或applicationWillEnterForeground中插入我的代码,虽然它运行正常,但我会暂时显示包含我要隐藏的文本的旧屏幕。
如何在重绘屏幕之前隐藏字段?
由于
iphaaw
答案 0 :(得分:2)
我认为问题是,iOS会在应用程序进入后台的瞬间捕获截图,因此动画会立即生效。
我认为这样做的唯一方法是在应用程序进入后台时隐藏/覆盖您的视图。
答案 1 :(得分:2)
在applicationWillResignActive:
中编写一些代码以“隐藏”您需要隐藏的内容。
答案 2 :(得分:0)
我遇到了类似的情况但是,我想要显示一个块代码屏幕来授予访问权限,而不是隐藏。无论如何,我认为该解决方案也适用于您的需求。
我经常在iOS应用程序中实现自定义基本视图控制器。因此,我没有处理applicationDidBecomeActive:
或applicationWillResignActive:
,而是设置此视图控制器以侦听等效通知:
@interface BaseViewController : UIViewController
- (void)prepareForGrantingAccessWithNotification:(NSNotification *)notification;
- (void)grantAccessWithNotification:(NSNotification *)notification;
@end
@implementation BaseViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self addNotificationHandler:@selector(grantAccessWithNotification:)
forNotification:UIApplicationDidBecomeActiveNotification];
[self addNotificationHandler:@selector(prepareForGrantingAccessWithNotification:)
forNotification:UIApplicationWillResignActiveNotification];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)prepareForGrantingAccessWithNotification:(NSNotification *)notification {
// Hide your views here
myCustomView.alpha = 0;
// Or in my case, hide everything on the screen
self.view.alpha = 0;
self.navigationController.navigationBar.alpha = 0;
}
- (void)grantAccessWithNotification:(NSNotification *)notification {
// This is only necessary in my case
[self presentBlockCodeScreen];
self.view.alpha = 1;
self.navigationController.navigationBar.alpha = 1;
...
}
@end