ios UIView 确实出现了?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5060958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:58:03  来源:igfitidea点击:

UIView did appear?

iphoneiosuiview

提问by nosuic

I'm wondering, is there a way to get a delegate or something, when a particular UIViewhas been shown on the screen ?

我想知道,当UIView屏幕上显示特定内容时,有没有办法获得代表或其他东西?

回答by Max

Try these:

试试这些:

– didAddSubview:
– willRemoveSubview:
– willMoveToSuperview:
– didMoveToSuperview
– willMoveToWindow:
– didMoveToWindow
- viewDidAppear:

回答by David 'mArm' Ansermot

If you manage your logic directly inside the UIView, use:

如果您直接在 UIView 内部管理逻辑,请使用:

- didMoveToSuperview

If you manage your logic inside a UIViewController, use :

如果您在 UIViewController 中管理您的逻辑,请使用:

- viewDidAppear:(BOOL)animated

回答by buxik

Swift version. Inside your UIView class just:

迅捷版。在您的 UIView 类中:

override func willMove(toWindow newWindow: UIWindow?) {
    super.willMove(toWindow: newWindow)

    if newWindow == nil {
        // UIView disappear
    } else {
        // UIView appear
    }
}

回答by Jacob Relkin

If you are managing the UIViewvia a UIViewController, then you can use the -viewDidAppear:method:

如果您UIView通过 a管理UIViewController,那么您可以使用以下-viewDidAppear:方法:

- (void) viewDidAppear:(BOOL) animated {
   //do stuff...
   [super viewDidAppear:animated];
}

回答by Ben

Another way to find out when a control is on screen is to subclass the View or Control and override drawRect...

找出控件何时出现在屏幕上的另一种方法是将 View 或 Control 子类化并覆盖drawRect...

However, it's called when it's drawn and not only when first shown. So it's only sometimes what you want. It worked for my case. Make sure to call super as well! =)

但是,它在绘制时被调用,而不仅仅是在第一次显示时调用。所以这只是有时你想要的。它适用于我的情况。一定要打电话给超级!=)