Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 尝试圆形图像,输出菱形形状?_Ios_Objective C_Uitableview_Uiimageview_Uiimage - Fatal编程技术网

Ios 尝试圆形图像,输出菱形形状?

Ios 尝试圆形图像,输出菱形形状?,ios,objective-c,uitableview,uiimageview,uiimage,Ios,Objective C,Uitableview,Uiimageview,Uiimage,我有一个奇怪的问题。我正在解析数据并提取图像的URL,然后将其设置为单元格的“imageView”。据我所知,我应该将“cornerRadius”的大小设置为图像高度的一半。因为我将数据拉入高度为100的表视图单元格,所以我将角半径设置为50 然而,当视图加载到图像的第一个初始加载上时,它们就变成了小钻石。当我旋转设备(它也旋转桌子视图)时,它会自动返回完整大小的图像,同时还具有圆度 这是初始载荷的示例图像 有人知道为什么会这样吗 这是我的tableView代码 - (UITableViewC

我有一个奇怪的问题。我正在解析数据并提取图像的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;
}

您需要将角半径设置为图像高度的一半,而不是表格单元格的高度。

您确定像自动布局这样的功能不会在运行时更改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);
试试这个

cell.imageView.layer.masksToBounds = YES;

cell.imageView.layer.cornerRadius = cell.imageView.frame.size.height/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];
把这个放到代码行

    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];

+我正要发同样的帖子,你打了我所以没发。干杯。@Dermot所以你给了我一个想法,使用NSLog查找高度输出为多少,它返回0.000000。我还关闭了Autolayout以查看它是否会改变任何内容,但它看起来没有。嗯,您的imageView是否为零?Obj-C可以向nil对象发送消息而不引发异常,因此如果imageView为nil,则当前代码不会导致错误。尝试NSLog(@“图像视图为%@”,(图像视图?@“非零”:@“零”);当单元格高度为100时,这是正确的。这是我一直在尝试的,但因为imageView边界大小高度返回0,所以它不起作用。我现在试图找出原因。请尝试设置imageView的contentmode属性。