UIView上存在哪些类似的功能方法(viewWillAppear)?

时间:2021-12-02 19:17:29

viewWillAppear is called on UIViewController when a view is about to be shown on screen. Is it possible to get similar callback on UIView?

当视图即将在屏幕上显示时,在UIViewController上调用viewWillAppear。是否有可能在UIView上获得类似的回调?

2 个解决方案

#1


41  

How about the following from the UIView reference

如何从UIView引用中得到以下内容

willMoveToSuperview:, didMoveToSuperview - Implement these methods as needed to track the movement of the current view in your view hierarchy.

willMoveToSuperview:,didMoveToSuperview - 根据需要实现这些方法,以跟踪视图层次结构中当前视图的移动。

this will at least tell you when it is added to a view hierarchy but there is no guarantee that the view hierarchy is presented/viewable.

这至少会告诉您何时将其添加到视图层次结构中,但不能保证视图层次结构是可呈现/可查看的。

#2


6  

No, but you can forward that notification to the desired view from your view controller.

不,但您可以从视图控制器将该通知转发到所需的视图。

#1


41  

How about the following from the UIView reference

如何从UIView引用中得到以下内容

willMoveToSuperview:, didMoveToSuperview - Implement these methods as needed to track the movement of the current view in your view hierarchy.

willMoveToSuperview:,didMoveToSuperview - 根据需要实现这些方法,以跟踪视图层次结构中当前视图的移动。

this will at least tell you when it is added to a view hierarchy but there is no guarantee that the view hierarchy is presented/viewable.

这至少会告诉您何时将其添加到视图层次结构中,但不能保证视图层次结构是可呈现/可查看的。

#2


6  

No, but you can forward that notification to the desired view from your view controller.

不,但您可以从视图控制器将该通知转发到所需的视图。