0

我正在尝试在表格视图单元格中创建一个简单的滚动视图。就像在应用商店中一样,但滚动更简单。

滚动视图正在显示,但它根本不滚动。我已经在谷歌上尝试了整个第一页和许多 stackoverflow 问题,似乎找不到我做错了什么。

 if (indexPath.row==0) {
    // Clearing out cell background
    [cell setBackgroundColor:[UIColor clearColor]];
    [cell.contentView setBackgroundColor:[UIColor clearColor]];

    // Imageviews for scrollview
    UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,123)];
    UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(320,0,320,123)];

    imageview1.image = [UIImage imageNamed:@"flash2.png"];
    imageview2.image = [UIImage imageNamed:@"IMG_2458.JPG"];

    // setting up scrollview
    self.scrollViewHeader = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320, 123)];
    self.scrollViewHeader.scrollEnabled = YES;
    self.scrollViewHeader.delegate = self;
    [self.scrollViewHeader setUserInteractionEnabled:YES];
    [self.scrollViewHeader setContentSize:CGSizeMake(320, 123)];
    [self.scrollViewHeader addSubview:imageview1];
    [self.scrollViewHeader addSubview:imageview2];
    [cell.contentView addSubview:self.scrollViewHeader];
}
else{
// Normal table cells.
...
}

提前感谢您的回答。

4

1 回答 1

3

为了让滚动视图滚动,它的内容大小必须大于它的边界。

你有:

self.scrollViewHeader = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320, 123)];

进而

[self.scrollViewHeader setContentSize:CGSizeMake(320, 123)];

在这种情况下,它们的大小相同,因此不会滚动。做:

self.scrollViewHeader = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,160, 123)];
[self.scrollViewHeader setContentSize:CGSizeMake(320, 123)];
于 2013-09-11T21:24:38.873 回答