繁体   English   中英

滚动UITableView时,图像内容中出现偏移

[英]Offset appears in image content when scrolling UITableView

滚动自定义UITableView单元格的TableView时出现一些奇怪的行为。

首次打开应用程序时,内容很好:

应用的初始加载

但是,如果我滚动视图,则嵌入式UIImageViews中会出现一些偏移量:

滚动后的状态

我已经删除了所有布局约束,但问题仍然存在。

由于这种原因,我感到茫然。 欢迎任何帮助!

这是我的cellForRowAtIndexPath代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *StrechCellIdentifier = @"StrechCell";

    //Place regular strechable cells.
    GFStrechCell *cell = [tableView dequeueReusableCellWithIdentifier:StrechCellIdentifier];

    if (cell == nil) {
        cell = (GFStrechCell*) [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:StrechCellIdentifier];
    }

    cell.nameLabel.text = @"Chez Julien";

    cell.descriptionLabel.text = @"A yummy place!";

    cell.descriptionLabel.hidden = YES;

    [cell.restaurantImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"restaurant%i.png", (indexPath.row%5 + 1)]]];

    if(indexPath.row % 2 == 0){
        [cell.favoriteButton.imageView setImage:[UIImage imageNamed:@"favoriteButtonPressed.png"]];
    } else {
        [cell.favoriteButton.imageView setImage:[UIImage imageNamed:@"favoriteButton.png"]];
    }

    return cell;
}

GFStrechCell只是调用的一个简单子类,其元素指向情节GFStrechCell中的IBOutlets:

故事板部分

奇怪,请尝试一下以查看其是否有效

下面:

[cell.restaurantImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"restaurant%i.png", (indexPath.row%5 + 1)]]];

尝试添加:

CGRect restaurantImageFrame = cell.restaurantImage.frame;
restaurantImageFrame.origin = CGPointZero; //or whatever it should be
cell.restaurantImage.frame = restaurantImageFrame;

这会将图像的原点设置为(0,0)。

编辑:您也可以尝试添加以下行。

[cell.restaurantImage sizeToFit];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM