Swift Pulse Animation

久未见 提交于 2020-05-25 05:31:41

问题


i'm trying to make a pulse animation, i've found this: ios - how to do a native "Pulse effect" animation on a UIButton and it was useful, but i need something else, so i have textfield, UITextField which has border, when you focus on it i want the border to change color, but in specific way i want it to start from center and then spread, i could not find the animation so i will try to demonstrate it by text:B = Black Y = Yellow. this is border:

BBBBBBB

border gets focused:

BBBYBBB

BBYYYBB

BYYYYYB

YYYYYYY

animation is over, focuse lost:

BYYYYYB

BBYYYBB

BBBYBBB

BBBBBBB

my code looks something like this:

let pulseAnimation = CABasicAnimation(keyPath: "borderColor")
    pulseAnimation.duration = 3
    pulseAnimation.fromValue = UIColor.darkGrayColor().CGColor
    pulseAnimation.toValue = UIColor.yellowColor().CGColor
    pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEasInEaseOut)
    pulseAnimation.autoreverses = true
    //pulseAnimation.repeatCount = FLT_MAX
    x.layer.sublayers![0].addAnimation(pulseAnimation, forKey: nil)

it works but i need it to do something else


回答1:


Here you go

let pulseAnimation = CABasicAnimation(keyPath: "opacity")
pulseAnimation.duration = 30
pulseAnimation.fromValue = 0
pulseAnimation.toValue = 1
pulseAnimation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
pulseAnimation.autoreverses = true
pulseAnimation.repeatCount =.greatestFiniteMagnitude
self.view.layer.add(pulseAnimation, forKey: nil)


来源:https://stackoverflow.com/questions/34761022/swift-pulse-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!