Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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 如何设置UIView的路径动画';谁的面具?_Ios_Swift_Animation_Uiview_Blur - Fatal编程技术网

Ios 如何设置UIView的路径动画';谁的面具?

Ios 如何设置UIView的路径动画';谁的面具?,ios,swift,animation,uiview,blur,Ios,Swift,Animation,Uiview,Blur,我已经在操场上探索这个问题好几天了,但没有找到任何解决办法 我一直在设法在模糊的视野中制造一个洞。现在我想知道如何为这个圆的半径设置动画,从而为模糊视图的遮罩路径设置动画 以下是我目前的代码: import Foundation import UIKit import PlaygroundSupport let contentRect = CGRect(x: 0, y: 0, width: 400, height: 400) let contentView = UIView(frame: co

我已经在操场上探索这个问题好几天了,但没有找到任何解决办法

我一直在设法在模糊的视野中制造一个洞。现在我想知道如何为这个圆的半径设置动画,从而为模糊视图的遮罩路径设置动画

以下是我目前的代码:

import Foundation
import UIKit
import PlaygroundSupport

let contentRect = CGRect(x: 0, y: 0, width: 400, height: 400)
let contentView = UIView(frame: contentRect)
contentView.backgroundColor = .white

PlaygroundPage.current.liveView = contentView

let image = UIImage(named: "landscape.jpg")
let imageView = UIImageView(frame: contentRect, image: image)
imageView.contentMode = .scaleAspectFill

let blur = UIBlurEffect(style: .light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = contentRect

let path = UIBezierPath(rect: contentRect)
let circle = UIBezierPath(ovalIn: CGRect(x: 50, y: 50, width: 300, height: 300))
path.append(circle)
path.usesEvenOddFillRule = true

let toPath = UIBezierPath(rect: contentRect)
let toCircle = UIBezierPath(ovalIn: CGRect(x: 150, y: 150, width: 100, height: 100))
toPath.append(toCircle)
toPath.usesEvenOddFillRule = true

let hole = CAShapeLayer()
hole.path = path.cgPath
hole.fillColor = UIColor.green.cgColor
hole.fillRule = kCAFillRuleEvenOdd

let mask = UIView(frame: contentRect)

contentView.addSubview(imageView)

contentView.addSubview(blurView)

mask.layer.addSublayer(hole)

blurView.mask = mask
我一直在尝试,但没有成功:

let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = hole.path
animation.toValue = toPath.cgPath
animation.duration = 2
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
hole.add(animation, forKey: nil)

CATransaction.begin()
CATransaction.disableActions()
hole.path = toPath.cgPath
CATransaction.commit()
还尝试了
UIView.animate(…
或提取
blurView.layer.sublayers
以将它们添加到我的
contentView
,但它只是变得一团糟

另一种方法是使用CGAffineTransform,我试过了,但是模糊被破坏了。另外,当我觉得非常接近解决方案时,我很难使用变通方法


任何帮助都将不胜感激!谢谢!

您也在真实设备上试用过吗?我也体验过一些动画,它们在操场上不起作用,但在设备上效果很好……我突然觉得自己很愚蠢。等等。好的,我刚刚检查过,我在应用程序、模拟器或设备上也遇到了同样的问题。不过谢谢您的建议。当然……挑战e接受:POK这里有一些发现…好消息是,通过设置
层的动画,而不是(
UIView的
mask
,可以找到一个通用的解决方案。坏消息是,这不适用于
UIVisualEffectView
(如其他问题所述):/