Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.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_Swift - Fatal编程技术网

如何在iOS中环绕阴影?

如何在iOS中环绕阴影?,ios,swift,Ios,Swift,我已经创建了一个圆形的UIView,它也应该有一个阴影。到目前为止,一切都正常,但在拐角处,阴影没有正确地圆化 如何绕过阴影角落 以下是代码和屏幕截图: popupView.layer.cornerRadius = 15 popupView.layer.shadowColor = UIColor.black.cgColor popupView.layer.shadowOffset = CGSize(width: 0, height: 0) popupView.layer.shadowOpaci

我已经创建了一个圆形的UIView,它也应该有一个阴影。到目前为止,一切都正常,但在拐角处,阴影没有正确地圆化

如何绕过阴影角落

以下是代码和屏幕截图:

popupView.layer.cornerRadius = 15

popupView.layer.shadowColor = UIColor.black.cgColor
popupView.layer.shadowOffset = CGSize(width: 0, height: 0)
popupView.layer.shadowOpacity = 0.3
popupView.layer.shadowRadius = 3.0
popupView.layer.shadowPath = UIBezierPath(rect: popupView.bounds).cgPath
popupView.layer.shouldRasterize = false

您需要将“视图层masksToBounds”值设置为true


popupView.layer.masksToBounds=true

您需要将视图层masksToBounds值设置为true

popupView.layer.masksToBounds=true

使用

popupView.layer.shadowPath = UIBezierPath(roundedRect: popupView.bounds, cornerRadius: 15).cgPath
而不是

popupView.layer.shadowPath = UIBezierPath(rect: popupView.bounds).cgPath
并添加一点阴影不透明度,如1.3,以更好地查看阴影。

使用

popupView.layer.shadowPath = UIBezierPath(roundedRect: popupView.bounds, cornerRadius: 15).cgPath
而不是

popupView.layer.shadowPath = UIBezierPath(rect: popupView.bounds).cgPath

添加一点阴影不透明度,比如1.3,以便更好地看到阴影。

所以,我基本上把你的代码扔到了操场上,玩了一会儿,我发现,我基本上可以删除
view.layer.shadowPath
,这样就行了

我还发现:

  • view.layer.masksToBounds=true
    未达到预期结果
  • view.layer.shadowPath=UIBezierPath(roundedRect:view.bounds,cornerRadius:15)。cgPath也可以工作,但会增加一个额外的故障点,因为如果在视图上更改
    cornerRadius
    属性,您需要记住设置该属性,或者添加一个变量来为这两个属性设定种子,但如果没有设置
    shadowPath
    ,它会产生相同的结果,这让我想知道为什么你们都会使用它

所以,我基本上把你的代码扔到了操场上,玩了一会儿,我发现,我基本上可以删除
view.layer.shadowPath
,这样就可以了

我还发现:

  • view.layer.masksToBounds=true
    未达到预期结果
  • view.layer.shadowPath=UIBezierPath(roundedRect:view.bounds,cornerRadius:15)。cgPath也可以工作,但会增加一个额外的故障点,因为如果在视图上更改
    cornerRadius
    属性,您需要记住设置该属性,或者添加一个变量来为这两个属性设定种子,但如果没有设置
    shadowPath
    ,它会产生相同的结果,这让我想知道为什么你们都会使用它

需要是
popupView.layer.shadowPath=UIBezierPath(roundedRect:popupView.bounds,cornerRadius:15.0)。cgPath
需要是
popupView.layer.shadowPath=UIBezierPath(roundedRect:popupView.bounds,cornerRadius:15.0)。cgPath