2017-04-11 1 views
1

나는 심장 박동을 상징하는 어떤 이미지가애니메이션 : 연속 하트 비트 모니터 라인은

heartbeat

당신이 이해하는 경우가 지속적으로 내보기에 나타납니다 그래서 난 내 하위 뷰에서 루프 그것에 노력하고있어 내가 평균. 지금까지 나는 그것을 내 서브 뷰에서 무한히 움직이게 만들었지 만 연속적이지는 않습니다. 오른쪽에서 완전히 사라진 후에는 다시 왼쪽에서부터 나타납니다. 그것이보기에 완전히 들어간대로 곧 실제 하트 비트를 상징합니다. 내 코드 내 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) 
+0

애니메이션의 하트 비트 이미지와 스크린 샷을 표시 할 수 있습니까? –

+0

캡쳐 화면을 추가했는데 하트 비트가 uiview에서 사라지는 것을 볼 수 있습니다. 그러나 같은 이미지의 두 인스턴스가 다른 것처럼 보이지 않도록 다른 인스턴스를 계속해서 따라야합니다. –

+0

@ UmarYaqub가이 문제를 해결합니까? –

답변

0

UIView를 타고 슈퍼보기로이 클래스를 설정합니다. 시작 애니메이션을 호출하고 필요할 때마다 애니메이션을 중단하십시오.

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