9

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

我发现了很棒的框架,但是它们使用 SKShapeNode,而 SKShapeNode 的性能对于实际部署的应用程序来说很糟糕

ProgressNode:非常酷的框架

4

1 回答 1

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

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

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

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

于 2016-10-03T21:01:56.427 回答