ios - UICollectionViewCell 内的 UIScrollView 不滚动

标签 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 具有水平滚动的全屏 UICollectionViewCellUICollectionView 上还有一个 UIGestureRecognizer:

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

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

最佳答案

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

关于ios - UICollectionViewCell 内的 UIScrollView 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31416674/

相关文章:

objective-c - 如何防止在 Objective-C 中为非物理属性创建变量?

ios - Alamofire/Swift - 如何在请求中添加 bool header 值

ios - NSString 中的对象太多? %@.%@.%@ 产生格式错误

objective-c - 如何限制使用的预处理定义的范围?

objective-c - 不可编辑的 NSTextfield,以使其在字符串太长时自动调整大小,例如英语单词到法语

ios - 如何从子类 UITableViewCell 调用 didSelectRowAtIndexPath

ios - UICollectionView 检测滚动方向并更改图像

ios - Xcode 7 GM 缺少 iOS 7 模拟器

ios - 如何在 appDelegate 中获取 CSSearchableItemAttributeSet

ios - 获取 UIScrollView 滚动到顶部