iPhone - UIScrollView inside UIView not scrolling

天大地大妈咪最大 提交于 2019-12-20 18:34:12

问题


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
-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

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


回答1:


scroll.contentSize= CGSizeMake(320,2700);// You can use contentsize according to your requirements

You have put here only scrollview code. So,I can't figure out what is wrong. Use following reference...

UIScrollView With UITextField

Hope, this will help you..




回答2:


[scrollView setContentSize:theSizeYouWantToScroll]



回答3:


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);


来源:https://stackoverflow.com/questions/10278112/iphone-uiscrollview-inside-uiview-not-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!