UICcrollView里面的UICollectionViewCell不滚动

时间:2015-07-14 20:29:17

标签: ios objective-c uiscrollview uicollectionview uicollectionviewcell

我这样设置UICollectionViewCell

    self.background = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)];
    self.background.userInteractionEnabled = YES;
    self.background.scrollEnabled = YES;
    self.background.showsVerticalScrollIndicator = YES;

    // configure image
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.background.frame.size.height)];

    [self.background addSubview:self.image];

    // configure title
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(5, 10, self.contentView.frame.size.width-10, 70)];
    [self.background addSubview:self.title];

    // configure description
    self.description = [[UILabel alloc] initWithFrame:CGRectMake(5, 80, self.contentView.frame.size.width-10, 20)];
    [self.background addSubview:self.description];

    self.textView = [[UIWebView alloc] initWithFrame:CGRectMake(0, self.image.frame.size.height+10, self.contentView.frame.size.width, 40)];
    self.textView.delegate = self;
    NSString *content = [NSString stringWithFormat:@"<html><head></head><body id='foo'>%@</body></html>", @"<p>kbafdj akdjfnadf jhadkfb ij daofhu adofh oj afoduuh oiad fohfd ouhadf dj aodfhj ah adlfk ohad ofladjhfl aojadf oadfh oadhf adfladf adfoadf oadfh aodfh a oadf aodf  afdjladf oad jladfl aodf alf d  adjfladf   adfj aldfkajdfljad aodfj adlfj ad aldjf adlfj al adfjadlfa d adf adf ad pajdf aldjf adkh pfbd fpqehf qehf qepd af pqif phhf q piiqihpsdhvpvqohro pdh wpvhqf lorem ipsum dfkbshbs k bfjsv ohfakdjb </p>"];
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [_textView loadHTMLString:content baseURL:baseURL];
    [self.background addSubview:_textView];

    [self addSubview:self.background];
    [self sendSubviewToBack:self.background];
    [self.background setContentSize:CGSizeMake(self.contentView.frame.size.width, 2*self.contentView.frame.size.height)];

UICollectionView功能全屏UICollectionViewCell水平滚动。 UIGestureRecognizer上还有一个UICollectionView

self.pinchRecognizer =
[[UIPinchGestureRecognizer alloc] initWithTarget:self                                    action:@selector(closeCell:)];
self.pinchRecognizer.delegate = self;
[_collectionView addGestureRecognizer:self.pinchRecognizer];

现在,UIScrollView不起作用。我不明白出了什么问题,所以如果有人能在这里帮助我,那就会膨胀。我做错了什么?

2 个答案:

答案 0 :(得分:2)

原来问题是我将UIScrollView发送到UICollectionViewCell的后面。删除[self sendSubviewToBack:self.background];解决了问题。

答案 1 :(得分:0)

UIWebView子视图可能正在处理平移手势。尝试在webview上禁用触摸交互。