From 7410a3e96d0ecb77740f3478d42f9057e1965089 Mon Sep 17 00:00:00 2001 From: Sherzod Khashimov Date: Tue, 8 Dec 2020 13:24:33 +0500 Subject: [PATCH] issue #11 fix --- Documentation/Changelog.md | 3 ++ .../Animation/SpinningWheelAnimator.swift | 40 ++++++++++--------- SwiftFortuneWheel.podspec | 2 +- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Documentation/Changelog.md b/Documentation/Changelog.md index 0f6fc7f..151e010 100644 --- a/Documentation/Changelog.md +++ b/Documentation/Changelog.md @@ -1,5 +1,8 @@ ## CHANGELOG +### 1.3.1 +- [Issue #11](https://github.com/sh-khashimov/SwiftFortuneWheel/issues/11): startRotationAnimation completion issue fix; + ### 1.3.0 - [Issue #6](https://github.com/sh-khashimov/SwiftFortuneWheel/issues/6): `pinImageView` collision effect animation added; diff --git a/Sources/SwiftFortuneWheel/Utils/Animation/SpinningWheelAnimator.swift b/Sources/SwiftFortuneWheel/Utils/Animation/SpinningWheelAnimator.swift index f81863f..e171731 100644 --- a/Sources/SwiftFortuneWheel/Utils/Animation/SpinningWheelAnimator.swift +++ b/Sources/SwiftFortuneWheel/Utils/Animation/SpinningWheelAnimator.swift @@ -75,15 +75,15 @@ class SpinningWheelAnimator: NSObject { onCenterCollision: onCenterCollision) let fillMode : String = CAMediaTimingFillMode.forwards.rawValue - let starTransformAnim = CAKeyframeAnimation(keyPath:"transform.rotation.z") - starTransformAnim.values = [0, fullRotationDegree * speed * speedAcceleration * CGFloat.pi/180 * rotationDirectionOffset] - starTransformAnim.keyTimes = [0, 1] - starTransformAnim.duration = 1 + let transformAnim = CAKeyframeAnimation(keyPath:"transform.rotation.z") + transformAnim.values = [0, fullRotationDegree * speed * speedAcceleration * CGFloat.pi/180 * rotationDirectionOffset] + transformAnim.keyTimes = [0, 1] + transformAnim.duration = 1 - let starRotationAnim : CAAnimationGroup = CAAnimationGroup(animations: [starTransformAnim], fillMode:fillMode) - starRotationAnim.repeatCount = Float.infinity - starRotationAnim.delegate = self - animationObject?.layerToAnimate?.add(starRotationAnim, forKey:"starRotationIndefiniteAnim") + let rotationAnim : CAAnimationGroup = CAAnimationGroup(animations: [transformAnim], fillMode:fillMode) + rotationAnim.repeatCount = Float.infinity + rotationAnim.delegate = self + animationObject?.layerToAnimate?.add(rotationAnim, forKey:"starRotationIndefiniteAnim") startedAnimationCount += 1 startCollisionDetectorsIfNeeded() @@ -112,20 +112,21 @@ class SpinningWheelAnimator: NSObject { onEdgeCollision: onEdgeCollision, onCenterCollision: onCenterCollision) - ////Star animation - let starTransformAnim = CAKeyframeAnimation(keyPath:"transform.rotation.z") - starTransformAnim.values = [0, rotation * rotationDirectionOffset * CGFloat.pi/180] - starTransformAnim.keyTimes = [0, 1] - starTransformAnim.duration = animationDuration - starTransformAnim.timingFunction = CAMediaTimingFunction(controlPoints: 0.0256, 0.874, 0.675, 1) - starTransformAnim.fillMode = CAMediaTimingFillMode.forwards - starTransformAnim.isRemovedOnCompletion = false + ////Start animation + let transformAnim = CAKeyframeAnimation(keyPath:"transform.rotation.z") + transformAnim.values = [0, rotation * rotationDirectionOffset * CGFloat.pi/180] + transformAnim.keyTimes = [0, 1] + transformAnim.duration = animationDuration + transformAnim.timingFunction = CAMediaTimingFunction(controlPoints: 0.0256, 0.874, 0.675, 1) + transformAnim.fillMode = CAMediaTimingFillMode.forwards + transformAnim.isRemovedOnCompletion = false + transformAnim.delegate = self if completionBlock != nil { - starTransformAnim.delegate = self + transformAnim.setValue("rotation", forKey:"animId") self.completionBlock = completionBlock } - animationObject?.layerToAnimate?.add(starTransformAnim, forKey:"starRotationAnim") + animationObject?.layerToAnimate?.add(transformAnim, forKey:"starRotationAnim") // to fix the problem of the layer's presentation becoming nil in detectors edgeCollisionDetector.animationObjectLayer = animationObject?.layerToAnimate @@ -147,7 +148,8 @@ class SpinningWheelAnimator: NSObject { extension SpinningWheelAnimator: CAAnimationDelegate { func animationDidStop(_ anim: CAAnimation, finished flag: Bool){ - if let completionBlock = self.completionBlock { + if let completionBlock = self.completionBlock, + let animId = anim.value(forKey: "animId") as? String, animId == "rotation" { completionBlock(flag) self.completionBlock = nil } diff --git a/SwiftFortuneWheel.podspec b/SwiftFortuneWheel.podspec index c4781e8..964f3a0 100644 --- a/SwiftFortuneWheel.podspec +++ b/SwiftFortuneWheel.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftFortuneWheel" - s.version = "1.3.0" + s.version = "1.3.1" s.summary = "Ultimate spinning wheel control that supports dynamic content and rich customization." s.description = <<-DESC Fortune spinning wheel that supports dynamic content and rich customization. Main Features: Dynamic content, support image, and text; Appearance customization; Drawn and animated using CoreGraphics; Dynamic layout.