所以基本上我有一个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];}}
答案 0 :(得分:0)
我能够通过删除主滚动视图的任何容器视图来解决这个问题