Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 矩形进度条快捷界面_Swift_Animation_Swiftui_Ios Animations_Swiftui Environment - Fatal编程技术网

Swift 矩形进度条快捷界面

Swift 矩形进度条快捷界面,swift,animation,swiftui,ios-animations,swiftui-environment,Swift,Animation,Swiftui,Ios Animations,Swiftui Environment,有人知道如何在swiftUI中创建矩形进度条吗 像这样的? 我试过这个: struct ProgressBar: View { @State var degress = 0.0 @Binding var shouldLoad: Bool var body: some View { RoundedRectangle(cornerRadius: cornerRadiusValue) .trim(from: 0.0, to:

有人知道如何在swiftUI中创建矩形进度条吗

像这样的?

我试过这个:

struct ProgressBar: View
{
    @State var degress = 0.0
    @Binding var shouldLoad: Bool

    var body: some View
    {
        RoundedRectangle(cornerRadius: cornerRadiusValue)
            .trim(from: 0.0, to: CGFloat(degress))
            .stroke(Color.Scheme.main, lineWidth: 2.0)
            .frame(width: 300, height: 40, alignment: .center)
            .onAppear(perform: shouldLoad == true ? {self.start()} : {})
    }

    func start()
    {
        Timer.scheduledTimer(withTimeInterval: 0.3, repeats: true)
        {
            timer in

            withAnimation
            {
                self.degress += 0.3
            }
        }
    }
}

下面是[0..1]范围进度指示器可能方法的简单演示

使用Xcode 11.4/iOS 13.4进行测试


下面是[0..1]范围进度指示器可能方法的简单演示

使用Xcode 11.4/iOS 13.4进行测试

可用于XCode 12

可用于XCode 12


展示你自己的尝试和参考,然后有人可以帮助你。展示你自己的尝试和参考,然后有人可以帮助你。嘿,谢谢你的帮助。在等待服务器响应时,有没有办法使用此加载?@Johanna,如果您知道预期数据的长度,那么只需将进度更新为接收数据的百分比即可。如果没有,那么像Undetermined这样的东西更合适。嘿,谢谢你的帮助。在等待服务器响应时,有没有办法使用此加载?@Johanna,如果您知道预期数据的长度,那么只需将进度更新为接收数据的百分比即可。如果没有,那么像Undetermined这样的东西更合适。
struct ProgressBar: View {
    @Binding var progress: CGFloat // [0..1]

    var body: some View {
        RoundedRectangle(cornerRadius: 10)
            .trim(from: 0.0, to: CGFloat(progress))
            .stroke(Color.red, lineWidth: 2.0)
            .animation(.linear)
    }
}

struct DemoAnimatingProgress: View {
    @State private var progress = CGFloat.zero

    var body: some View {
        Button("Demo") {
            if self.progress == .zero {
                self.simulateLoading()
            } else {
                self.progress = 0
            }
        }
        .padding()
        .background(ProgressBar(progress: $progress))
    }

    func simulateLoading() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
            self.progress += 0.1
            if self.progress < 1.0 {
                self.simulateLoading()
            }
        }
    }
}
import SwiftUI

//MARK: - ProgressBar
struct ContentView: View {
    
    @State private var downloaded = 0.0
    
    var body: some View {
        ProgressView("Downloaded...", value: downloaded, total: 100)
    }
}

//MARK: - Circular ProgressBar
struct ContentView: View {
        
    @State private var downloaded = 0.0
        
    var body: some View {
        ProgressView("Downloaded...", value: downloaded, total: 100)
            .progressViewStyle(CircularProgressViewStyle())
    }
}