0

コレクションビューセルに境界線付きで表示されている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);
}

これがスクリーンショットです:!http://m.mirror.co/collection.png

4

2 に答える 2

0

UICollectionView の collectionViewLayout プロパティで何が起こっていますか? UICollectionView が表示されているセルをパディングしていると推測しています。

于 2012-12-14T23:44:46.163 に答える
0

LLDBデバッグの目的で、アプリを一時停止して実行することは非常に貴重であることがわかりました...

po [[UIWindow keyWindow] _autolayoutTrace]

これにより、各ビュー オブジェクトへのポインタが得られます。それから私は走ります...

po [0xabcd123 constraints]

...実行時に知らなかった自動制約が追加されたかどうかを確認します。また、セルとビューのフレーム サイズを取得して、それらが一致するかどうかを確認できます。自動制約をプログラムで削除し、ビューをセルに固定する新しい制約を適用する必要がある場合があります。ビューセルをビューからビューに「フリップ」しているときに、これに遭遇しました。

init または IB で自動制約をオフにすることを忘れないでください...

[self.imageview setTranslatesAutoresizingMaskIntoConstraints:NO];

幸運を!

于 2012-12-15T19:02:33.123 に答える