如何在 applicationDidBecomeActive 之前更新屏幕?

发布于 2024-11-05 08:13:27 字数 200 浏览 0 评论 0原文

当用户通过将应用程序切换到前台来激活应用程序时,我需要隐藏屏幕上的某些内容。

我尝试在 applicationDidBecomeActive 或 applicationWillEnterForeground 中插入代码,尽管它运行正常,但旧屏幕上会暂时显示我想要隐藏的文本。

如何在屏幕重绘之前隐藏该字段?

谢谢伊帕奥

I need to hide something on the screen when the user has activates the application by switching it to the foreground.

I have tried inserting my code within applicationDidBecomeActive or applicationWillEnterForeground and although it runs OK the old screen with the text I want to hide is displayed momentarily.

How can I hide the field before the screen is redrawn?

Thanks

iphaaw

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乖乖兔^ω^ 2024-11-12 08:13:27

我认为问题是,iOS会在你的应用程序进入后台时捕获屏幕截图,因此动画会立即生效。

我认为做到这一点的唯一方法是在应用程序进入后台时隐藏/覆盖您的视图。

I think the problem is, iOS will capture a screenshot from your app in the moment it goes to the background, so the animation will work in an instant.

The only way in my opinion to do this is to hide / cover your view in moment the app goes to the background.

ら栖息 2024-11-12 08:13:27

applicationWillResignActive: 中编写一些代码来“隐藏”您需要隐藏的任何内容。

Write some code in applicationWillResignActive: to 'hide' whatever you need to hide.

走走停停 2024-11-12 08:13:27

我遇到了类似的情况,但我不想隐藏,而是想显示一个块代码屏幕来授予访问权限。无论如何,我认为该解决方案也适用于您的需求。

我经常在我的 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

I faced a similar situation but, instead of hiding, I wanted to show a block code screen to grant access. Anyway I think that the solution also applies to your needs.

I often implement a custom base view controller in my iOS applications. So instead of dealing with applicationDidBecomeActive: or applicationWillResignActive: I setup this view controller to listen for the equivalent notifications:

@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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文