【问题标题】:Mask video with background color on SwiftUI View在 SwiftUI 视图上使用背景颜色遮罩视频
【发布时间】:2022-11-01 11:02:54
【问题描述】:

所以我试图在我的一个视图上屏蔽和使用透明度,但我似乎无法弄清楚如何正确屏蔽一半的视图,然后让其余的保持清晰。

所以这是我正在使用的代码:

// Onboarding Video
OnboardingVideoView(
    videoName: "OnboardingVideo"
)
.mask(alignment: .bottom) {
    LinearGradient(
        stops: [
            Gradient.Stop(color: .clear, location: .zero),
            Gradient.Stop(color: .accentColor, location: 1.0)
        ],
        startPoint: .bottom,
        endPoint: .center
    )
}
.ignoresSafeArea(.all)

我得到以下输出:


问题

  1. 我无法让.accentColor 工作,它是绿色的(它一直显示白色)。
  2. 我想让底部更坚固一点,如下所示。

    这是我的目标:

    所有帮助将不胜感激!我只需要一种颜色.accentColor,其余的都是透明的。

【问题讨论】:

    标签: swift swiftui


    【解决方案1】:

    看起来您正在寻找的是overlay,而不是mask

    .overlay(
        LinearGradient(
                stops: [
                    Gradient.Stop(color: .clear, location: .zero),
                    Gradient.Stop(color: .accentColor, location: 0.75)
                ],
                startPoint: .top,
                endPoint: .bottom
            )
    )
    

    【讨论】:

      猜你喜欢
      • 2018-01-06
      • 2020-03-02
      • 2022-01-25
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 2020-09-29
      • 1970-01-01
      相关资源
      最近更新 更多