xcode iPhone - UIView 内的 UIScrollView 不滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10278112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone - UIScrollView inside UIView not scrolling
提问by nachiket talwalkar
I have a UIView
which contains lot of labels, buttons, textviews. But there is a certain part of that UIView
that I want to make scrollable.Here is how the structure of my nib is.
我有一个UIView
包含很多标签、按钮、文本视图的文件。但是UIView
我想让其中的某些部分可滚动。这是我笔尖的结构。
-UIVIew
-UIImageView - backgroundImage
-UILabels
-UIButtons
-UIScrollView
-UITextViews
Are touch events getting assigned to somewhere else? Here is a code of my scrollview which I have written in viewDidLoad
. I only want the textview inside UIScrollview
to be scrollable
触摸事件是否被分配到其他地方?这是我用viewDidLoad
. 我只希望里面的 textviewUIScrollview
是可滚动的
scrollView.delegate = self;
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
scrollView.autoresizesSubviews=YES;
[scrollView setContentMode:UIViewContentModeScaleAspectFit];
[scrollView addSubview:textview];
Am I mising something? is my approach right?
我错过了什么吗?我的方法对吗?
Thanks and regards
感谢致敬
采纳答案by Nitin
scroll.contentSize= CGSizeMake(320,2700);
// You can use contentsize according to your requirements
scroll.contentSize= CGSizeMake(320,2700);
// 可以根据自己的要求使用 contentsize
You have put here only scrollview code. So,I can't figure out what is wrong. Use following reference...
您只在此处放置了滚动视图代码。所以,我无法弄清楚出了什么问题。使用以下参考...
Hope, this will help you..
希望能帮到你..
回答by adali
[scrollView setContentSize:theSizeYouWantToScroll]
回答by pbibergal
You better should let the compiler figure out the height, instead of setting it yourself.
您最好让编译器计算出高度,而不是自己设置。
CGFloat height = 0;
for (UIView *v in _scrollView.subviews) {
height += v.frame.size.height;
}
_scrollView.contentSize = CGSizeMake(self.view.frame.size.width, height);