UITextView 在分页 UIScrollView 内滚动不起作用
Posted
技术标签:
【中文标题】UITextView 在分页 UIScrollView 内滚动不起作用【英文标题】:UITextView Scrolling inside a paging UIScrollView not working 【发布时间】:2015-05-05 13:35:21 【问题描述】:所以基本上我有一个 UIScrollView,在其中我有一个 UIView 作为内容视图,滚动视图已启用分页设置,在内容视图内我在顶部有 UIImage 视图,在它下面我有一个 UITextView,文本视图可以有比它自己的高度更大的文本,所以它应该滚动 这是我的代码。
-(void)setUpMainScroller
if(MainScroller != nil)
[[self.MainScrollViewContainer viewWithTag:80] removeFromSuperview] ;
MainScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.MainScrollViewContainer.frame.size.height)];
MainScroller.tag = 80 ;
MainScroller.backgroundColor = [UIColor clearColor] ;
MainScroller.showsHorizontalScrollIndicator = NO;
MainScroller.delegate = self ;
MainScroller.pagingEnabled = YES ;
MainScroller.clipsToBounds = YES;
MainScroller.delaysContentTouches = NO;
CGFloat paperWidth = MainScroller.frame.size.width;
NSDictionary * item = [elements objectAtIndex:selectedIndex] ;
NSArray * temp = item[@"Sub"] ;
NSUInteger numberOfPapers = [temp count];
count = (int)numberOfPapers ;
CGFloat por =( self.view.frame.size.width-40)/(CGFloat)numberOfPapers;
[self setupIndicatorWithPaperWidth:por andPaperCount:(int)numberOfPapers] ;
for (NSUInteger i = 0; i < numberOfPapers; i++)
CGFloat rest = self.MainScrollViewContainer.frame.size.height ;
CGFloat labl =rest - 140+15 ;
CGFloat contentheight = 140+15 + rest ;
UIView * content = [[UIView alloc] initWithFrame:CGRectMake(paperWidth*i, 0, self.view.frame.size.width, contentheight)] ;
content.clipsToBounds = YES ;
UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, paperWidth-40, 140)];
image.backgroundColor = [UIColor grayColor] ;
if(i == 0 )
image.backgroundColor = [UIColor redColor] ;
else if (i==1)
image.backgroundColor = [UIColor blueColor] ;
else if(i ==2)
image.backgroundColor = [UIColor greenColor] ;
CGFloat imageheight = image.frame.size.height +15 ;
CGFloat labelheight = contentheight - imageheight ;
UITextView * textview= [[UITextView alloc] initWithFrame:CGRectMake( 20 ,image.frame.origin.y + image.frame.size.height +15, paperWidth - 40 , 20)] ;
[textview setBackgroundColor:[UIColor grayColor]] ;
[textview setText:label.text];
[textview setUserInteractionEnabled:YES] ;
textview.delegate = self ;
textview.contentSize = CGSizeMake(textview.bounds.size.width , textview.bounds.size.height+50) ;
[content addSubview:image] ;
[content addSubview:@"LONG TEXT"] ;
[MainScroller addSubview:content] ;
//[content bringSubviewToFront:textview] ;
[textview setScrollEnabled:YES];
// [MainScroller addSubview:image];
CGSize contentSize = CGSizeMake(paperWidth * numberOfPapers, MainScroller.bounds.size.height);
MainScroller.contentSize = contentSize;
[self.MainScrollViewContainer addSubview:MainScroller];
self.MainScrollViewContainer.scrollview =MainScroller ;
[self.MainScrollViewContainer bringSubviewToFront:MainScroller];
【问题讨论】:
【参考方案1】:我能够通过删除主滚动视图的任何容器视图来解决此问题
【讨论】:
以上是关于UITextView 在分页 UIScrollView 内滚动不起作用的主要内容,如果未能解决你的问题,请参考以下文章