Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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 四舍五入UIImage方法不适用于';不行?_Ios_Uiimageview_Uiimage_Drawing - Fatal编程技术网

Ios 四舍五入UIImage方法不适用于';不行?

Ios 四舍五入UIImage方法不适用于';不行?,ios,uiimageview,uiimage,drawing,Ios,Uiimageview,Uiimage,Drawing,使用此方法,无论我为CGFloat参数输入什么,0,1,甚至100。我的UIImage始终有一个圆角,即使我将参数设置为0。UIImage所在的MyUIImageView被设置为缩放以填充,如果这有任何区别 不管怎样,这个方法有什么问题吗 //Rounded UIImage - (UIImage*)roundCorneredImage: (UIImage*)orig radius:(CGFloat) r { UIGraphicsBeginImageContextWithOptio

使用此方法,无论我为
CGFloat
参数输入什么,
0
1
,甚至
100
。我的
UIImage
始终有一个圆角,即使我将参数设置为
0
UIImage
所在的My
UIImageView
被设置为缩放以填充,如果这有任何区别

不管怎样,这个方法有什么问题吗

    //Rounded UIImage
- (UIImage*)roundCorneredImage: (UIImage*)orig radius:(CGFloat) r {
    UIGraphicsBeginImageContextWithOptions(orig.size, NO, 0);
    [[UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, orig.size} 
                                cornerRadius:r] addClip];
    [orig drawInRect:(CGRect){CGPointZero, orig.size}];
    UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return result;
}

你的方法很好用。我在我的环境中试过。所以,错误应该位于代码段之外的某个地方。您确定要将返回的图像用于UIImageView吗?是,因为否则我的UIImageView中将没有图像。但这很奇怪,因为即使我使用0,我的图像仍然是圆形的!我是在黑暗中拍摄的,但是否有可能您意外地将cornerRadius应用于UIImageView的图层?与您的代码片段完全相同的代码片段在我的环境中完全可以正常工作。是的,这就是问题所在,谢谢!现在可以了!