ContentBlurView

轻松获得类似 watchOS 10 上的酷炫渐变模糊效果

Example

安装

可在 iOS 17+ 或 watchOS 10+ 上使用。

  1. 在 Xcode 中,从“文件”菜单中选择“Add Packages…”(添加包…)。
  2. 在搜索字段中输入 https://github.com/hiddevdploeg/ContentBlurView
  3. 单击“Add Package”(添加包)(将依赖规则设置为“Up to Next Major Version”(直到下一个主版本))
  4. 添加包后,您将能够使用以下代码在您的项目中导入 ContentBlurView:
import ContentBlurView

如何使用

您可以将 ContentBlurView 与任何 View 一起使用

ContentBlurView {
    // Any view goes here
}
.ignoresSafeArea(edges: .all) // for fullscreen enjoyment

方向

您可以决定模糊应该从哪一侧开始:.topBlur.leadingBlurtrailingBlur.bottomBlur。 默认值为 .bottomBlur

文本

建议使用 HierarchicalShapeStyle 作为文本的 .foregroundStyle,这将使其在背景中更加鲜明。

示例

import MapKit
struct ContentView: View {
    var body: some View {
            TabView {

            // Example with image and blur on top
            ContentBlurView(direction: .topBlur) {
                AsyncImage(url: URL(string: "https://picsum.photos/800"))
            }
            .ignoresSafeArea(edges: .all)

            // Example with Map and text on top of it
            ZStack(alignment: .bottom) {
                ContentBlurView {
                    Map(interactionModes: .rotate) {
                        Marker("Apple Park", coordinate: CLLocationCoordinate2D(latitude: 37.334268, longitude: -122.008715))
                    }
                    .mapStyle(.imagery)
                }
                .ignoresSafeArea(edges: .all)
                Text("Apple Park")
                    .font(.headline)
                    .foregroundStyle(.primary)
                    .padding()
            }
        }
        .tabViewStyle(.verticalPage)
    }
}

作者

此库由 Hidde van der Ploeg 创建。 欢迎在 TwitterMastodon 上联系我。

许可证

ContentBlurView 在 MIT 许可证下可用。

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.