gpt4 book ai didi

ios - 动画 : continuous heartbeat monitor lines

转载 作者:行者123 更新时间:2023-11-28 08:12:33 26 4
gpt4 key购买 nike

我有一个象征心跳的图像

heartbeat

我正在尝试在我的 subview 中循环播放它,这样如果您理解我的意思,它就会不断出现在我的 View 中。到目前为止,我已经让它在我的 subview 上无限地出现和移动,但是它不是连续的,因为它只是在完全离开右侧的 View 后才从左侧再次出现,因为我希望它再次出现一旦它完全进入视野,它就象征着真正的心跳。我的代码在我的 viewDidLoad 上看起来像这样:

self.heartbeatLoading.frame.origin = CGPoint(x: 0 - heartbeatLoading.frame.size.width, y: 10)    
let animation: UIViewAnimationOptions = [.repeat, .curveLinear]

UIView.animate(withDuration: 5.0, delay: 0, options: animation, animations: {
self.heartbeatLoading.frame = self.heartbeatLoading.frame.offsetBy(dx: self.view.frame.width + self.heartbeatLoading.frame.width, dy: 0.0)
}, completion: nil)

最佳答案

取一个 UIView 并将此类设置为 super View 。调用开始动画并在需要时停止动画。

@IBDesignable class Pulse : UIView
{
var animatingView : UIView?
@IBInspectable var pulseImage: UIImage = UIImage(named: "defaultImage")!{
didSet {
animatingView = UIView(frame: self.bounds)
let imgView = UIImageView(frame : self.bounds)
animatingView?.clipsToBounds = true
animatingView?.addSubview(imgView)
self.addSubview(animatingView!)
}
}
func startAnimationWith(duration : Double = 0.5)
{
if animatingView != nil
{
animatingView?.frame = CGRect(x: 0, y: 0, width: 0, height: (animatingView?.frame.size.height)!)
UIView.animate(withDuration: duration, delay: 0, options: .repeat, animations: {
self.animatingView?.frame = CGRect(x: 0, y: 0, width: (self.animatingView?.frame.size.width)!, height: (self.animatingView?.frame.size.height)!)
}, completion: { (isDone) in

})
}
}
func stopAnimation()
{
if animatingView != nil
{
self.animatingView!.layer.removeAllAnimations()
}
}
override init(frame : CGRect) {
super.init(frame : frame)
}
convenience init() {
self.init(frame:CGRect.zero)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}

关于ios - 动画 : continuous heartbeat monitor lines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43357647/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com