iOS7上的UICollectionViewCell中的UIImageView自动布局问题,但在iOS8上它';没关系

iOS7上的UICollectionViewCell中的UIImageView自动布局问题,但在iOS8上它';没关系,ios,uiimageview,uiimage,autolayout,uicollectionviewcell,Ios,Uiimageview,Uiimage,Autolayout,Uicollectionviewcell,在ImageView中缩小图像大小时出现问题。 在CollectionViewCell中,具有带约束的ImageView:两个水平空间和两个垂直空间 第一个屏幕是iOS7,第二个屏幕是iOS8。 ImageURL这是一个自定义类,用于按URL加载图像,它工作正常,还可以设置一个类似 _clothesImageView.image = [UIImage imageNamed:@"imageName.png"]; - (void)configCellWithClothesMode

在ImageView中缩小图像大小时出现问题。 在CollectionViewCell中,具有带约束的ImageView:两个水平空间和两个垂直空间
第一个屏幕是iOS7,第二个屏幕是iOS8。

ImageURL这是一个自定义类,用于按URL加载图像,它工作正常,还可以设置一个类似

    _clothesImageView.image = [UIImage imageNamed:@"imageName.png"];

    - (void)configCellWithClothesModel:(ClothesModel *)clothesModel
    {
        [_clothesImageView setImageURL:[NSURL URLWithString:clothesModel.imageURL]];
    }
服装模型:

- (instancetype)initWithDict:(NSDictionary *)dict
{
    self = [super init];
    if (self)
    {
        _isShop = @(YES);
        self.title = [self checkNullAndNill:dict[kTitle]];
        self.info = [self checkNullAndNill:dict[kDescription_Short]];
        self.artNumber = [self checkNullAndNill:dict[kArtNumber]];
        self.afLink = [self checkNullAndNill:dict[kDeeplink1]];
        self.imageURL = [self checkNullAndNill:dict[kImg_url]];
        _isCart = @(NO);
    }
    return self;
}


//==============================================================================


- (id)checkNullAndNill:(id)object
{
    if (object == nil)
        return @"";
    else if (object == [NSNull null])
        return @"";
    else
        return object;
}


//==============================================================================


- (UICollectionViewCell *)configCellWithType:(NSString *)type collectionView:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath
{
    ClothesCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[type isEqualToString:@"Outfits"] ? @"CellOutfits" : @"Cell" forIndexPath:indexPath];
    [cell configCellWithClothesModel:self];
    return cell;
}


//==============================================================================

这实际上取决于自动布局设置。
UIImageView
s通常根据其固有内容大小设置大小,该内容大小设置为其承载的图像的大小。
如果集合视图单元格没有足够数量的约束,则所看到的内容可能取决于不同iOS上的autolayout引擎实现。

另外,请检查注释中所述的图像视图的内容模式。

在Xcode6 Interface builder中,不会显示单元格的内容视图。 CollectionViewCell在iOS7中具有内容视图,其框架设置为默认值(0,0,50,50)。
您需要在CollectionViewCell子类中添加此代码,以便contentView可以调整自身大小

- (void)awakeFromNib
{
   [super awakeFromNib];
   self.contentView.frame = self.bounds;
   self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

给我们一些ClothesModel类的代码。特别是图像部分。放一些代码。您正在iPhone 5或iPhone 6中运行代码?@hris.to done。自定义类工作正常。@AshishKakkad iPhone 6不支持iOS7。我在所有使用iOS7的设备上运行,都有相同的问题。我想试试[imgView.layer setMaskToBound:YES]如果它不工作,那么试试[imgView setContentMode:]在contentMode中有UIViewContentModeScaleSpectFill、UIViewContentModeScaleSpectFit、,UIViewContentModeScaleToFill和这三个选项中的一个可能对您有所帮助我已经删除了所有约束,它在iOS7上工作,但当我在iPhone 6或6+上运行时,图像不会增加大小。您不需要删除约束,但可以正确设置它们例如,让我们假设imageview应该延伸到整个单元格内容视图。imageview的右常量为前导、尾随、顶部和底部,常量为0。是的,我做了。这是以前的事,回答得很好!帮了我很多忙。你提醒了我奶奶,她在我需要帮助时给了我解决办法!