我们有一排139x127图像,在我们的集合视图单元格中显示边框。我们尝试了UIViewContentModeScaleAspectFill(和Fit),但它仍然显示边框。
代码如下: // uicollectionviewcell
(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self = [super initWithFrame:frame];
if (self) {
// Initialization code
NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"ProfilePhotoCell" owner:self options:nil];
if ([arrayOfViews count] < 1) {
return nil;
}
if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
return nil;
}
self = [arrayOfViews objectAtIndex:0];
}
[self.imageView setContentMode:UIViewContentModeScaleAspectFill];
return self;
}
return self;
}
// uicollectionview/viewcontroller
// 1
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
// 2
CGSize retval = CGSizeMake(100, 66);
return retval;
}
// 3
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(20, 0, 0, 0);
}
答案 0 :(得分:0)
UICollectionView的collectionViewLayout属性发生了什么?我猜UICollectionView正在填充它正在显示的单元格。
答案 1 :(得分:0)
出于调试目的,我发现通过暂停应用并运行来使用LLDB
是无价的......
po [[UIWindow keyWindow] _autolayoutTrace]
这将为您提供指向每个视图对象的指针。然后我会跑...
po [0xabcd123 constraints]
...查看是否在运行时添加了您不知道的任何自动约束。此外,您可以获取单元格和视图的帧大小,看看它们是否匹配。您可能需要以编程方式删除自动约束并应用将视图固定到单元格的新约束。我在使视图单元从视图“翻转”到视图时遇到了一些问题。
不要忘记关闭init或IB中的自动约束......
[self.imageview setTranslatesAutoresizingMaskIntoConstraints:NO];
祝你好运!