添加到 UIScrollView 的 viewController 未调用其 viewDidAppear 方法
我有一个 UIScrollView,它通过 viewController1.view 和 viewController2.view 属性添加了 2 个不同的视图。我希望在屏幕上出现 viewController1.view 或 viewController2.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像 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.
您将需要使用滚动视图的 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