WWPulseLayer

main

Use CAReplicatorLayer to achieve pulse animation effects.
William-Weng/WWPulseLayer

WWPulseLayer

Swift-5.6 iOS-14.0 tag Swift Package Manager-SUCCESS LICENSE

WWPulseLayer

dependencies: [
    .package(url: "https://github.com/William-Weng/WWPulseLayer.git", .upToNextMajor(from: “1.0.0"))
]

可用函式

函式 說明
start() 啟動動畫
stop() 結束動畫

Example

import UIKit
import WWPrint
import WWPulseLayer

final class ViewController: UIViewController {

    enum SliderType: Int {
        case Count = 101
        case MaxRadius = 102
        case Duration = 103
        case Interval = 104
        case MaxAlpha = 105
    }
    
    enum SegmentType: Int {
        case Orientation = 201
        case Color = 202
    }
    
    @IBOutlet weak var layerView: UIView!
    
    var pulseLayer: WWPulseLayer!

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        pulseLayer = WWPulseLayer()
        
        pulseLayer.frame = CGRect(origin: layerView.center, size: .zero)
        pulseLayer.start()
        
        layerView.layer.addSublayer(pulseLayer)
    }
    
    @IBAction func valueSliderAction(_ sender: UISlider) {
        
        guard let type = SliderType(rawValue: sender.tag) else { return }
        
        switch type {
        case .Count: pulseLayer.pulseCount = Int(sender.value)
        case .MaxRadius: pulseLayer.maxRadius = CGFloat(sender.value)
        case .Duration: pulseLayer.animationDuration = Double(sender.value)
        case .Interval: pulseLayer.animationInterval = Double(sender.value)
        case .MaxAlpha: pulseLayer.maxAlpha = CGFloat(sender.value)
        }
    }
    
    @IBAction func valueSegmentedAction(_ sender: UISegmentedControl) {
        
        guard let type = SegmentType(rawValue: sender.tag) else { return }
        
        switch type {
        case .Orientation: 
            pulseLayer.pulseOrientation = (sender.selectedSegmentIndex == 0) ? .out : .in
        case .Color:
            pulseLayer.inColor = (sender.selectedSegmentIndex == 0) ? .blue : .red
            pulseLayer.outColor = (sender.selectedSegmentIndex == 0) ? .blue : .yellow
        }
    }
}

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 10:20:28 GMT-0900 (Hawaii-Aleutian Daylight Time)