轻松获得类似 watchOS 10 上的酷炫渐变模糊效果
可在 iOS 17+ 或 watchOS 10+ 上使用。
https://github.com/hiddevdploeg/ContentBlurView
。import ContentBlurView
您可以将 ContentBlurView
与任何 View
一起使用
ContentBlurView {
// Any view goes here
}
.ignoresSafeArea(edges: .all) // for fullscreen enjoyment
您可以决定模糊应该从哪一侧开始:.topBlur
、.leadingBlur
、trailingBlur
或 .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 创建。 欢迎在 Twitter 或 Mastodon 上联系我。
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.