9

I want to creat a simple circular loader animation circle and border around it which is disappearing

I found great frameworks but they use SKShapeNode and SKShapeNode performance is terrible for actual deployed app

ProgressNode: Very cool framework

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 に答える