添加到 UIScrollView 的 viewController 未调用其 viewDidAppear 方法

发布于 2024-11-09 14:22:44 字数 561 浏览 0 评论 0原文

我有一个 UIScrollView,它通过 viewController1.viewviewController2.view 属性添加了 2 个不同的视图。我希望在屏幕上出现 viewController1.viewviewController2.view 时收到通知。尝试使用 viewDidAppear 方法,但它没有被调用。

错过了什么?有什么想法吗?

谢谢!

//Add xViewController to scrollView
[scrollView addSubview:firstViewController.view];
[scrollView addSubview:secondViewController.view];
[scrollView addSubview:thirdViewController.view];
[scrollView addSubview:fourthViewController.view];

I have a UIScrollView which has 2 different views added via viewController1.view and viewController2.view properties. I want to be notified when viewController1.view or viewController2.view has appeared on screen. Tried to use the viewDidAppear method but it does not gets called.

Missed something? Any ideas?

Thanks!

//Add xViewController to scrollView
[scrollView addSubview:firstViewController.view];
[scrollView addSubview:secondViewController.view];
[scrollView addSubview:thirdViewController.view];
[scrollView addSubview:fourthViewController.view];

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

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

发布评论

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

评论(2

々眼睛长脚气 2024-11-16 14:22:44

像 viewDidAppear 这样的方法只能在视图控制器被推入堆栈时被触发,而不是单个视图。抱歉,我无法真正建议您如何跟踪将它们显示到屏幕上 - 除非您初始化并隐藏它们的内容,然后一旦准备好,您就会知道您只需一个 .hidden = NO 调用即可显示它们。

Methods such as viewDidAppear can only be fired when view controllers are pushed to the stack, not singular views. Sorry I can't really advise on how else you could track getting them to the screen - unless you initialised and hide their contents, then once this was ready you'd know you were just one .hidden = NO call away from showing them.

爱,才寂寞 2024-11-16 14:22:44

您将需要使用滚动视图的 contentOffset 来计算 UIScrollViewDelegate 函数scrollViewDidScroll 中正在显示哪个视图。

查看 PageControl 的实现,了解 UIScrollView 的工作原理。PageControl 演示

You will need to use contentOffset of the scrollview to calculate which view is being displayed in the UIScrollViewDelegate function scrollViewDidScroll.

Look at the implementation of PageControl to understand how UIScrollView works.PageControl Demo

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