3

奇妙な問題が発生しています。データを解析して画像の URL を取得し、それをセルの ' imageView' に設定しています。私が理解できることから、「 」のサイズをcornerRadius画像の高さの半分に設定する必要があります。高さ 100 のテーブル ビュー セルにデータを取り込むため、角の半径を 50 に設定しています。

しかし、画像の最初の初期読み込みでビューが読み込まれると、小さなひし形として表示されます。デバイスを回転すると (テーブル ビューも回転します)、丸みのあるフルサイズの画像が自動的に表示されます。

これは、初期ロードの例の画像です。

ここに画像の説明を入力

なぜこれが起こるのか誰か知っていますか?

これが私のtableViewコードです

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    NSDictionary *generatedUsers = [self.randomlyGeneratedUsersArray objectAtIndex:indexPath.row];
    NSURL *url = [NSURL URLWithString:[generatedUsers valueForKeyPath:@"user.picture"]];
    cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", [generatedUsers valueForKeyPath:@"user.name.first"], [generatedUsers valueForKeyPath:@"user.name.last"]];
    cell.detailTextLabel.text = [generatedUsers valueForKeyPath:@"user.location.street"];
    [cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder"]];

    cell.imageView.layer.cornerRadius = 50.0f;
    cell.imageView.layer.masksToBounds = YES;

    return cell;
}
4

4 に答える 4

6

自動レイアウトのようなものが実行時に imageView の高さを変更していないと確信していますか? 次のように角の半径を設定してみてください。

cell.imageView.layer.corderRadius = (cell.imageView.bounds.size.height /2);
//And to try figure out what's going on...
NSLog(@"Cell imageview height: %f",cell.imageView.bounds.size.height);
于 2013-10-31T04:55:12.180 に答える
1

この 2 行のコードの代わりに

    cell.imageView.layer.cornerRadius = 50.0f;
    cell.imageView.layer.masksToBounds = YES; 

これをコード行に入れます

[cell.imageView.layer setCornerRadius:cell.imageView.frame.size.width/2];
 [cell.imageView setClipsToBounds:YES];
于 2013-10-31T09:09:45.180 に答える
0

角の半径は、表のセルではなく、画像の高さの半分に設定する必要があります。

于 2013-10-31T04:54:45.360 に答える
0

これを試して。

cell.imageView.layer.masksToBounds = YES;

cell.imageView.layer.cornerRadius = cell.imageView.frame.size.height/2;
于 2013-10-31T05:48:26.550 に答える