Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.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 动画:连续心跳监视器线路_Ios_Swift_Uianimation_Heartbeat - Fatal编程技术网

Ios 动画:连续心跳监视器线路

Ios 动画:连续心跳监视器线路,ios,swift,uianimation,heartbeat,Ios,Swift,Uianimation,Heartbeat,我有一个象征心跳的图像 我试着在我的子视图中循环它,所以如果你理解我的意思,它会持续出现在我的视图中。到目前为止,我已经让它在我的子视图上无限地出现和移动,但是它不是连续的,因为它只是在完全离开右侧视图后从左侧再次出现,我希望它在完全进入视图后立即再次出现,因此它象征着一个实际的心跳。我的代码在我的viewDidLoad上看起来像这样: self.heartbeatLoading.frame.origin = CGPoint(x: 0 - heartbeatLoading.frame.size

我有一个象征心跳的图像

我试着在我的子视图中循环它,所以如果你理解我的意思,它会持续出现在我的视图中。到目前为止,我已经让它在我的子视图上无限地出现和移动,但是它不是连续的,因为它只是在完全离开右侧视图后从左侧再次出现,我希望它在完全进入视图后立即再次出现,因此它象征着一个实际的心跳。我的代码在我的
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
并将该类设置为超级视图。调用start animation并在需要时停止动画

@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)
    }
}

取一个
UIView
并将该类设置为超级视图。调用start animation并在需要时停止动画

@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)
    }
}

你能展示你的心跳图像和动画截图吗?我添加了一个截图,您可以看到,心跳正在从uiview中消失,就像它假设的那样,但我希望它的另一个实例紧跟其后,这样它看起来就不像是同一个视图的两个不同实例image@UmarYaqub这个问题解决了吗?你能显示你的心跳图像和你的动画截图吗?我添加了一个截图,您可以看到,心跳正在从uiview中消失,就像它假设的那样,但我希望它的另一个实例紧跟其后,这样它看起来就不像是同一个视图的两个不同实例image@UmarYaqub这个问题解决了吗?