Animador de gradientes de SwiftUI SwiftUI gradient animator
Entre 2 y 5 paradas. Se ordenan por posición al generar el código.
Between 2 and 5 stops. They are sorted by location in the generated code.
El borde queda fijo; solo se mueven los puntos interiores.
The border stays fixed; only interior points move.
Cómo leer la animación How to read the animation
- Linear: la dirección oscila alrededor del ángulo base. El código anima
startPointyendPoint. - Angular: el gradiente gira una vuelta completa cada duración. El código anima
startAngleyendAngle. - Radial: el centro se desplaza en círculo. El código anima
center. - Mesh: solo se mueven los puntos interiores; el borde queda fijo para conservar el encuadre. El código anima
points. - La vista previa de Mesh usa un canvas aproximado; comprueba el resultado en un dispositivo.
- Linear: the direction oscillates around the base angle. The code animates
startPointandendPoint. - Angular: the gradient rotates a full turn every duration. The code animates
startAngleandendAngle. - Radial: the center drifts in a circle. The code animates
center. - Mesh: only interior points move; the border stays fixed to preserve the frame. The code animates
points. - The Mesh preview uses an approximate canvas; check the result on a device.
—
La vista previa es una aproximación. El código usa TimelineView(.animation) (iOS 15+); para cambios puntuales, valora withAnimation y verifica el resultado en un dispositivo.
The preview is an approximation. The code uses TimelineView(.animation) (iOS 15+); for one-off state changes, consider withAnimation and check the result on a device.
Cómo se anima en SwiftUI How it animates in SwiftUI
TimelineView(.animation) vuelve a evaluar la vista en cada fotograma. Es la forma más directa de animar un MeshGradient o de calcular puntos y ángulos manualmente. Para cambios de estado puntuales, withAnimation suele ser más barato si los valores son animables. TimelineView requiere iOS 15+.
MeshGradientrequiere iOS 18+, iPadOS 18+, macOS 15+, tvOS 18+, watchOS 11+ y visionOS 2+.- Los puntos se ordenan de izquierda a derecha y de arriba abajo. Los bordes deben cubrir 0...1 para no dejar huecos; si no lo hacen, usa
background. smoothsColorscontrola la interpolación suave ycolorSpacedecide si se mezcla en dispositivo o perceptual.- Anima pocos puntos y mantén la malla pequeña. Un
TimelineViewa la frecuencia de refresco puede costar más que una animación de estado; para cambios lentos, valoraTimelineView(.periodic). - Respeta Reduce Motion: si está activo, muestra un gradiente estático o reduce la animación.
Referencias: MeshGradient, TimelineView y Create custom visual effects with SwiftUI (WWDC24).
TimelineView(.animation) re-evaluates the view every frame. It is the most direct way to animate a MeshGradient or to calculate points and angles manually. For one-off state changes, withAnimation is usually cheaper when the values are animatable. TimelineView requires iOS 15+.
MeshGradientrequires iOS 18+, iPadOS 18+, macOS 15+, tvOS 18+, watchOS 11+, and visionOS 2+.- Points are ordered left to right and top to bottom. Border points should cover 0...1 to avoid gaps; if they do not, use
background. smoothsColorscontrols smooth interpolation, andcolorSpacechooses device or perceptual blending.- Animate few points and keep the mesh small. A display-rate
TimelineViewcan cost more than a state animation; for slow changes, considerTimelineView(.periodic). - Respect Reduce Motion: show a static gradient or reduce the animation when it is enabled.
References: MeshGradient, TimelineView, and Create custom visual effects with SwiftUI (WWDC24).