HomeiOS Developmentios - create 4-5 ripples repeatedly and repeat the method after...

ios – create 4-5 ripples repeatedly and repeat the method after some delay in Swift


I’m engaged on an iOS app the place I have to create ripple impact on a UIView. I’m able to create the ripple impact however I’m not capable of customise it. That is what I wish to achive:

enter image description here

That is my present output

enter image description here

What I wish to obtain is create 4-5 ripples repeatedly after which after some delay one other 4-5 ripple and repeat the method infinitely. However at the moment I’m solely capable of create 1 ripple (it does go infinitely).

Right here is my code:

func addRipple(rView: UIView) {
    let path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: rView.bounds.dimension.width, top: rView.bounds.dimension.top))

    let shapePosition = CGPoint(x: rView.bounds.dimension.width / 2.0, y: rView.bounds.dimension.top / 2.0)
    let rippleShape = CAShapeLayer()
    rippleShape.bounds = CGRect(x: 0, y: 0, width: rView.bounds.dimension.width, top: rView.bounds.dimension.top)
    rippleShape.path = path.cgPath
    rippleShape.fillColor = UIColor.clear.cgColor
    rippleShape.strokeColor = UIColor.systemBlue.cgColor
    rippleShape.lineWidth = 1
    rippleShape.place = shapePosition
    rippleShape.opacity = 0
    
    rView.layer.addSublayer(rippleShape)

    let scaleAnim = CABasicAnimation(keyPath: "remodel.scale")
    scaleAnim.fromValue = NSValue(caTransform3D: CATransform3DIdentity)
    scaleAnim.toValue = NSValue(caTransform3D: CATransform3DMakeScale(2, 2, 1))

    let opacityAnim = CABasicAnimation(keyPath: "opacity")
    opacityAnim.fromValue = 1
    opacityAnim.toValue = nil

    let animation = CAAnimationGroup()
    animation.animations = [scaleAnim, opacityAnim]
    animation.timingFunction = CAMediaTimingFunction(title: CAMediaTimingFunctionName.easeOut)
    animation.period = 1
    animation.repeatCount = Float.infinity
    animation.isRemovedOnCompletion = false
    rippleShape.add(animation, forKey: "rippleEffect")
}

I feel I’m very shut however I’m not capable of determine it out.

Thanks prematurely.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments