当UIView可见时,如何获得通知? [英] How can I get notified when a UIView becomes visible?

查看:200
本文介绍了当UIView可见时,如何获得通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以获得通知,回调或一些其他方法来调用一个方法,每当UIView变得可见的用户,即当UIScrollview是一些UIViews的超视图,并且这样的UIView的ViewController

Is there a way to get a notification, a callback or some other means to call a method whenever a UIView becomes visible for the user, i.e. when a UIScrollview is the superview of some UIViews, and the ViewController of such a UIView shall get notified when its view is now visible to the user?

我知道可能的,但不是那么优雅的解决方案,检查ScrollView滚动到哪个位置(通过UIScrollViewDelegate方法),并计算任何一个子视图是否可见...

但是我正在寻找一个更通用的方法来做这个。

I am aware of the possible, but not so elegant solution of checking to which position the ScrollView scrolled (via UIScrollViewDelegate-methods) and compute if either one of the subviews is visible...
But I'm looking for a more universal way of doing this.

推荐答案

如果你的视图是展示行为,它应该在视图控制器中。在视图控制器上,每次视图出现时将调用viewDidAppear方法。

If your view is exhibiting behavior, it should be within a view controller. On a view controller, the viewDidAppear method will be called each time the view appears.

- (void)viewDidAppear:(BOOL)animated

这篇关于当UIView可见时,如何获得通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆