简体   繁体   English

获取滚动视图中内容视图子视图的高度

[英]get height of a content view subview in a scroll view

I'm trying to understand how scroll views works with autolayout. 我试图了解滚动视图如何与自动布局一起工作。 I have understood that there are 2 ways of getting it to work, the pure version or the mixed version. 我知道有两种方法可以使它正常工作,即纯版本或混合版本。 I'm trying the mixed version, following the recepi on this page: https://developer.apple.com/library/ios/technotes/tn2154/_index.html 我正在尝试混合版本,遵循此页面上的收据: https : //developer.apple.com/library/ios/technotes/tn2154/_index.html

I have a scroll view with a contentView as the first subview. 我有一个将contentView作为第一个子视图的滚动视图。 According to the apple recepi i need to do this: 根据苹果recepi我需要这样做:

[scrollView setContentSize:CGMakeSize(contentWidth,contentHeight)];

I have set my contentView to be 600 pt high, but when i run the app it just logs the screen size and not the actual size of the contentView. 我将contentView设置为600 pt高,但是当我运行该应用程序时,它只会记录屏幕尺寸,而不是contentView的实际尺寸。

NSLog(@"%@", NSStringFromCGSize(self.scrollViewContent.bounds.size));

This logs {320, 568} 此日志{320,568}

What am i doing wrong? 我究竟做错了什么?

According to your comments, the view hierarchy as below. 根据您的评论,视图层次如下。 Concept behind this, even if you change content size of your scroll view, it won't change size of all subviews. 其背后的概念是,即使您更改滚动视图的内容大小,也不会更改所有子视图的大小。

---ScrollView
    -----scrollViewContent
          ------OtherViews

If you want to change size of content view according to content size, just change size too for content view frame. 如果要根据内容大小更改内容视图的大小,也可以更改内容视图框架的大小。

CGRect newFrame = self.scrollViewContent.frame;
frame.size = scrollView.contentSize;
self.scrollViewContent.frame = newFrame;

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

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