小编Chr*_*ris的帖子

SwiftUI 中的淡入淡出图像似乎不起作用

我想实现一个动画背景,在 SwiftUI 中对一堆图像进行淡入淡出。

我已经使用以下代码片段设法让一组颜色在它们之间很好地交叉淡入淡出,但是如果我用一组图像替换颜色数组,则相同的方法不起作用。图像被替换,但没有动画。然而 Color 和 Image 都属于 some View 类型,对吗?

以下工作:

struct ImageBackgroundView: View {

  @State private var index = 0

  private let colors:[Color] = [.red, .blue, .green, .orange, .pink, .black]
  private let timer = Timer.publish(every: 5, on: .main, in: .common).autoconnect()

  var body: some View {
    colors[self.index]
      .animation(.easeInOut(duration: 1))
      .onReceive(timer) { _ in
        print(self.index)
        self.index += 1
        if self.index > 5 { self.index = 0 }
      }
  }
Run Code Online (Sandbox Code Playgroud)

但是,如果我用 [Images] 类型的数组替换 [Color] 数组,如下所示,图像会转换,但交叉淡入淡出似乎不起作用:

struct ImageBackgroundView: View {

  @State private …
Run Code Online (Sandbox Code Playgroud)

ios swift swiftui xcode11

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

如果在单元测试中则跳过 python 中的代码

我当前的脚本调用外部脚本来执行某些任务。我想在单元测试中检查到目前为止的代码,但实际上不运行外部脚本。如果代码作为单元测试的一部分运行,是否有某种方法可以告诉脚本有效地跳过以下块?

python unit-testing python-unittest

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

标签 统计

ios ×1

python ×1

python-unittest ×1

swift ×1

swiftui ×1

unit-testing ×1

xcode11 ×1