小编Joh*_*nna的帖子

如何在 SwiftUI 中显示文本 2 秒然后隐藏它?

你好,有人可以帮我吗?如何在 SwiftUI 中显示文本 2 秒,然后将其隐藏?

我有文字

文本(“我的文本”)

我希望这段文字在 2 秒后被删除

和另一个出现在文本位置的元素

swiftui

9
推荐指数
1
解决办法
3908
查看次数

矩形进度条swiftUI

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

像这样的东西? https://i.stack.imgur.com/CMwB3.gif

我试过这个:

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
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

animation swift ios-animations swiftui swiftui-environment

1
推荐指数
1
解决办法
1382
查看次数