计算scrollview的contentsize

Calculate the contentsize of scrollview(计算scrollview的contentsize)
本文介绍了计算scrollview的contentsize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个滚动视图作为表格视图单元格的详细视图.我正在通过界面生成器创建的详细视图上有多个视图,例如标签、按钮等.我通过界面生成器创建的是静态的.我把所有东西都放在高度 480 的视图上.

I'm having a scrollview as the detailedview of tableview cell. There are multiple views on the detailedview like labels, buttons etc. which I'm creating through interface builder. What I'm creating through interface builder is static. I'm putting everything on a view of height 480.

我的详细视图上的标签具有可以扩展到任意长度的动态文本.问题是我需要设置滚动视图的内容大小,我需要它的高度.

A label on my detailedview is having dynamic text which can extend to any length. The problem is that I need to set the scrollview's content size for which I need its height.

如果内容是动态的,我应该如何设置滚动视图的高度?

How shall I set scrollview's height provided the content is dynamic?

推荐答案

你可以尝试使用scrollview'ers ContentSize.它对我有用,我在使用动态内容的控件时遇到了同样的问题.

You could try to use the scrollview'ers ContentSize. It worked for me and I had the same problem with the control using dynamic content.

    // Calculate scroll view size
float sizeOfContent = 0;
int i;
for (i = 0; i < [myScrollView.subviews count]; i++) {
    UIView *view =[myScrollView.subviews objectAtIndex:i];
    sizeOfContent += view.frame.size.height;
}

// Set content size for scroll view
myScrollView.contentSize = CGSizeMake(myScrollView.frame.size.width, sizeOfContent);

我在控制器中名为 viewWillAppear 的方法中为包含滚动视图的视图执行此操作.这是我在调用 super 上的 viewDidLoad 之前做的最后一件事.

I do this in the method called viewWillAppear in the controller for the view that holds the scrollview. It is the last thing i do before calling the viewDidLoad on the super.

希望它能解决你的问题.

Hope it will solve your problem.

//汉内斯

这篇关于计算scrollview的contentsize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)