UITextView在分页UIScrollView中滚动不起作用

阿卜杜勒·阿曼·塔赫尔·巴达里(Abd Al-rhman Taher Badary)

所以基本上我有一个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];}}
阿卜杜勒·阿曼·塔赫尔·巴达里(Abd Al-rhman Taher Badary)

我能够通过删除主滚动视图的任何容器视图来解决此问题

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章