大佬教程收集整理的这篇文章主要介绍了swift – 为UIViewPropertyAnimator的fractionComplete设置动画以模糊背景,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用fractionComplete属性来设置平移UIView时要模糊多少的过程.
animator = UIViewPropertyAnimator(duration: 1,curve: .linear) { self.blurEffectView.effect = nil }
并且模糊度的变化值在0.0-1.0之间.
animator?.fractionComplete = blurValue
但是当我取消平移手势时,我希望模糊从其所处的位置动画回到无模糊(例如,〜> 1.0),持续时间为0.4毫秒.
现在我只是在取消平移手势时将fractionComplete设置为1.0.相反,我想要动画它.
我已经尝试了UIView.animate(withDuration ..但它不会影响UIViewPropertyAnimators fractionComplete,这是模糊UIVisualEffectView的唯一方法.
有任何想法吗?
要解决此问题,您可以执行以下操作:
animator.startAnimation() // This will change the `state` from inactive to active animator.pauseAnimation() // This will change `isRunning` BACk to false,but the `state` will remain as active // Now any call of `fractionComplete` should update your view correctly! animator.fractionComplete = /* your value here */
这是一个可以玩的游乐场片段:
let liveView = UIView(frame: CGRect(x: 0,y: 0,width: 400,height: 50)) liveView.BACkgroundColor = .white PlaygroundPage.current.needsIndefiniteExecution = true PlaygroundPage.current.liveView = liveView let square = UIView(frame: CGRect(x: 0,width: 50,height: 50)) square.BACkgroundColor = .red liveView.addSubview(squarE) let animator = UIViewPropertyAnimator.init(duration: 5,curve: .linear) animator.addAnimations { square.frame.origin.x = 350 } let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .dark)) blurView.frame = liveView.bounds liveView.addSubview(blurView) animator.addAnimations { blurView.effect = nil } // If you want to restore the blur after it was animated,you have to // safe a reference to the effect which is manipulated let effect = blurView.effect animator.addCompletion { // In case you want to restore the blur effect if $0 == .start { blurView.effect = effect } } animator.startAnimation() animator.pauseAnimation() DispatchQueue.main.asyncAfter(deadline: .Now() + 2) { animator.fractionComplete = 0.5 } DispatchQueue.main.asyncAfter(deadline: .Now() + 4) { // decide the direction you want your animation to go. // animator.isReversed = true animator.startAnimation() }
以上是大佬教程为你收集整理的swift – 为UIViewPropertyAnimator的fractionComplete设置动画以模糊背景全部内容,希望文章能够帮你解决swift – 为UIViewPropertyAnimator的fractionComplete设置动画以模糊背景所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。