如何从 NavigationController 堆栈将消息发送回 UIScrollView?

发布于 2024-12-12 05:17:39 字数 1212 浏览 2 评论 0原文

我的视图控制器的结构如下:

> UIWindow 
> - RootViewController with UIScrollView (2 pages, pagingEnabled)
> -- UINavigationController (in the first page of the scrolling view)
> --- HomePageViewController (plus other ViewControllers pushed on the stack)  
> -- MinutiaViewController (second page)

UIScrollView 将 UInavigationController 作为子视图 [scrollView addSubview:navController.view];

在我的场景中我想:

  • 将新视图推送到 UINavigationViewController 后禁用 UIScrollView 滚动 (scrollEnable=NO)
  • 一旦弹出新视图并且 UINavigationController 再次显示其根,再次启用 UIScrollView (scrollEnable=YES) (HomePageViewController)

我想出了如何在推送新视图时禁用scrollView滚动。

但是无法弄清楚当新视图从堆栈中弹出时如何启用scrollView滚动。

到目前为止我尝试过

1 触发viewWillAppear;视图将消失;手动并发送 从 HomePageViewController 的 viewWillAppear 发送到 UIScrollView 的消息 例如

    [self.navigationController.parentViewController performSelector:@selector(enableScrollAgain)];  

2 将 RootViewController 指定为 UINavigationController 委托来处理其 活动

到目前为止似乎都不起作用。感谢所有建议!

My view controllers are structured like this:

> UIWindow 
> - RootViewController with UIScrollView (2 pages, pagingEnabled)
> -- UINavigationController (in the first page of the scrolling view)
> --- HomePageViewController (plus other ViewControllers pushed on the stack)  
> -- MinutiaViewController (second page)

UIScrollView holds the UInavigationController as a subview
[scrollView addSubview:navController.view];

In my scenario I want to:

  • disable UIScrollView scrolling (scrollEnable=NO) once a new view is pushed onto the UINavigationViewController
  • enable UIScrollView again (scrollEnable=YES) once the new view is popped and the UINavigationController shows its root again
    (HomePageViewController)

I figured out how to disable the scrollView scrolling when pushing a new view.

But cannot figure out how to enable the scrollView scrolling when the new view pops off the stack.

So far I tried

1 triggering viewWillAppear; viewWillDisappear; manually and sending a
message to UIScrollView from HomePageViewController's viewWillAppear
e.g.

    [self.navigationController.parentViewController performSelector:@selector(enableScrollAgain)];  

2 designated the RootViewController as a UINavigationController delegate to handle its
events

None seems to work so far. All advice appreciated!

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

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

发布评论

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

评论(1

夏末 2024-12-19 05:17:39

您尝试过使用通知吗?您可以添加 RootView 来观察导航控制器的通知,当您收到该通知时,您可以禁用滚动。查看通知中心。

希望这有帮助

Have you tried using Notifications ? You could add the RootView to observe a notification form the navigation controller, when you get that notification you can disable scrolling. Look into NotificationCenter.

Hope this helps

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