繁体   English   中英

使用嵌入式视图控制器调整UIScrollView的contentSize的大小

[英]Resize contentSize of UIScrollView with embedded view controller

我有一个带有UIScrollView的UIViewController(MasterViewController),在顶部有一个标题视图,在下面有一个容器。

当我嵌入任何childViewController(例如EmbeddedViewController)时,显然需要调整UIScrollView的contentSize。 为了调整大小,我需要等到正确放置嵌入式视图后再进行设置

scrollView.contentSize.height = embeddedViewController.tableView.contentSize.height + HeaderView.frame.height;

何时(在MasterViewController中)嵌入任何EmbeddedViewController之后何时可以更新scrollView.contentSize?

我以为我可以打电话

[embeddedViewController layoutIfNeeded];

...就在我将其嵌入到masterView中之前,但是不正确地设置了scrollView contentSize。 您对UIScrollViews中的动态长度containerViews有任何想法或最佳做法吗?

在此处输入图片说明

viewDidLayoutSubviews方法中提供scrollview contentsize

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width,350);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM