如何在没有SKShapeNode的情况下实现循环加载器

gra*_*pe1 9 sprite-kit skshapenode swift

我想创建一个简单的圆形装载机动画圆圈和它周围的边框正在消失

我找到了很棒的框架,但他们使用SKShapeNode和SKShapeNode性能对于实际部署的应用程序来说非常糟糕

ProgressNode:非常酷的框架

小智 0

您可以在 UIImageView 中使用 UIView 并将“加载圆圈”作为图像,然后旋转它。这是一个示例类:

import UIKit

class CircularLoadingView: UIView {

    @IBOutlet weak var rotatingImage: UIImageView!
    let duration: Double = 1

    func startAnimation() {
        let animation = CABasicAnimation(keyPath: "transform.rotation.z")
        animation.toValue = NSNumber(floatLiteral:  M_PI * 2.0 * duration)
        animation.duration = duration
        animation.isCumulative = true
        animation.repeatCount = Float(CGFloat.greatestFiniteMagnitude)
        rotatingImage.layer.add(animation, forKey: "animationKey")

        UIView.animate(withDuration: duration, animations: {
            self.alpha = 1
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

只需添加一个 UIView 并将 CircularLoadingView 设置为自定义类。添加一个 UIImageView,设置要旋转的图像,设置出口和约束,看看会发生什么。

但通过这种尝试,你需要一个图像,你必须创建或找到它。

如果这对您没有帮助,也许这个旧的raywenderlich 教程可以。他们展示了如何使用 CAShapeLayer 制作圆形指示器。