Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swiftui show custom loading spinner

import Foundation
import SwiftUI

struct ActivityIndicator: View {
    
    @State private var isAnimating: Bool = false
    
    var body: some View {
        GeometryReader { (geometry: GeometryProxy) in
            ForEach(0..<5) { index in
                Group {
                    Circle()
                        .frame(width: geometry.size.width / 5, height: geometry.size.height / 5)
                        .scaleEffect(calcScale(index: index))
                        .offset(y: calcYOffset(geometry))
                }.frame(width: geometry.size.width, height: geometry.size.height)
                    .rotationEffect(!self.isAnimating ? .degrees(0) : .degrees(360))
                    .animation(Animation
                                .timingCurve(0.5, 0.15 + Double(index) / 5, 0.25, 1, duration: 1.5)
                                .repeatForever(autoreverses: false))
            }
        }
        .aspectRatio(1, contentMode: .fit)
        .onAppear {
            self.isAnimating = true
        }
    }
    
    func calcScale(index: Int) -> CGFloat {
        return (!isAnimating ? 1 - CGFloat(Float(index)) / 5 : 0.2 + CGFloat(index) / 5)
    }
    
    func calcYOffset(_ geometry: GeometryProxy) -> CGFloat {
        return geometry.size.width / 10 - geometry.size.height / 2
    }
    
}
Comment

PREVIOUS NEXT
Code Example
Swift :: remove grey background when selecting cells from uitableview swift after selection 
Swift :: Swift String Example 
Swift :: swift class init 
Swift :: Adapt sfsymbol to frame swiftui 
Swift :: Swift Check if an Array is Empty 
Swift :: didselectrowatindexpath not called swift 
Swift :: how to figure out ios vesion swift 
Ruby :: rails get list of tables 
Ruby :: ruby array group by attribute 
Ruby :: rails get current path 
Ruby :: ruby measure time 
Ruby :: how to decrypt credentials in rails 
Ruby :: Your Ruby version is 2.6.8, but your Gemfile specified 2.7.5 
Ruby :: if contains ruby 
Ruby :: ruby capitalize first character of sentence 
Ruby :: remove first element from an array ruby 
Ruby :: ruby array to string with commas 
Ruby :: how to delete database in rails 
Ruby :: rails array sort 
Ruby :: ruby extract number from string 
Ruby :: starting delayed_jobs in local rails 3 
Ruby :: ruby array remove by index 
Ruby :: heroku run rails 
Ruby :: ruby routes 
Ruby :: DEPRECATION WARNING: Sprockets method `register_engine` is deprecated. 
Ruby :: rails string to html 
Ruby :: number of trailing zeros in a factorial of a number. 
Ruby :: sentry send error manually ruby 
Ruby :: my rails server exits automatically and now gives the following error: 
Ruby :: ruby on rails recover data in params with form tag 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =