简体   繁体   English

UIScrollView没有滚动另一个子视图的内容

[英]UIScrollView is not scrolling the content of another subview

Hi everyone. 嗨,大家好。 I dragged a UIScrollView to my storyboard, then I added a UIView on top of that UIScrollView . 我将UIScrollView拖动到情节提要中,然后在该UIScrollView顶部添加了一个UIView This UIView loads another subview dynamically depending on what the server throws to this app. UIView根据服务器向该应用程序抛出的内容动态加载另一个子视图。

The problem is the UIScrollView is not scrolling the content, even though I made the loaded UIView bigger than the UIScrollView . 问题是,即使我使加载的UIView大于UIScrollViewUIScrollView也不滚动内容。 I'm not invoking [myScroller addSubView:myUiView] . 我没有调用[myScroller addSubView:myUiView] Am I doing it right? 我做对了吗? Thanks in advance! 提前致谢!

您必须设置滚动视图的内容大小。

Add this in your view controller. 在您的视图控制器中添加它。

- (void) viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    myScroller.contentSize = CGSizeMake(CGRectGetMaxX(myUiView.frame), CGRectGetMaxY(myUiView.frame));
}

For every time you change the content try calling 每次更改内容时,请尝试致电

//removeFromSuperview the UIView was set as content view
self.myScroller.contentSize = self.myUiView.frame.size;
[myScroller addSubView:myUiView];

Don't forget to link both views on Interface Builder 不要忘记在Interface Builder上链接两个视图

PS: In this apporach the subView must not be inside the scrollView on IB PS:在此方法中,subView不得位于IB的scrollView内

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

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