MeshGradient новая View в SwiftUI (iOS 18+ 🤬). А у меня так и не доходили руки до него.
Я пытался повторить эффект от Apple AI без Metal и понял что на MeshGradients можно сделать за 10 минут.
Зацените какой анимированный градиент сделал (Там буквально один маленький фалик).
Смотреть нужно на статус бар.
struct AppleMeshGradient: View {
@State private var points: [SIMD2<Float>] = [
[0.0, 0.0], [0.5, 0.0], [1.0, 0.0],
[0.0, 0.5], [0.5, 0.5], [1.0, 0.5],
[0.0, 1.0], [0.5, 1.0], [1.0, 1.0],
]
@State private var colors: [Color] = [
firstColor, secondColor, secondColor,
secondColor, secondColor, firstColor,
thirdColor, firstColor, thirdColor
]
var body: some View {
TimelineView(.animation(minimumInterval: 2.0)) { time in
MeshGradient(
width: 3,
height: 3,
points: points,
colors: colors
)
.ignoresSafeArea()
.onChange(of: time.date, { oldValue, newValue in
withAnimation(.linear(duration: 2)) {
var newColors = colors
newColors.shuffle()
colors = newColors
}
})
}
}
}
Вы уже попробовали MeshGradient? Скидывайте что красивого получилось ☺️
PS: Скоро сделаю пост про приложение в которое я добавлял анимацию
#blog