Questions tagged [swiftui-animation]

The tag has no usage guidance, but it has a tag wiki.

Filter by
Sorted by
Tagged with
23 votes
2 answers
12k views

How can I reverse the slide transition for a SwiftUI animation?

I'm working on a sequence of screens that should change on a button press and should slide in/out from right to left. Everything is working nicely except the .slide transition makes it move in from ...
noranraskin's user avatar
  • 1,327
23 votes
3 answers
14k views

SwiftUI - Animate view transition and position change at the same time

I have a yellow container with a green view inside. I want to move the container while also hiding/showing the inner green view, with an animation. Currently, I'm using .offset for the movement, and ...
aheze's user avatar
  • 28k
21 votes
2 answers
15k views

This SwiftUI animation should only fade out. Why does it move to the right?

I'm having a hard time understanding why this happens. I reduced the problem to its minimum expression. I have a single Text view, that when removed, should just fade out. The .transition(.opacity) ...
kontiki's user avatar
  • 39.1k
10 votes
2 answers
846 views

Use match geometry effect when navigating between views using a navigation link

My home view contains a CustomView that opens a detailed view via a NavigationLink when tapped. The detailed view also contains the CustomView, just in a different location. Can I use the match ...
yambo's user avatar
  • 1,667
9 votes
2 answers
3k views

SwiftUI Animation from @Published property changing from outside the View

SwiftUI offers .animation() on bindings that will animate changes in the view. But if an @Published property from an @ObserveredObject changes 'autonomously' (e.g., from a timer), while the view will ...
c_booth's user avatar
  • 2,215
9 votes
3 answers
6k views

SwiftUI - Sliding Text animation and positioning

On my journey to learn more about SwiftUI, I am still getting confused with positioning my element in a ZStack. The goal is "simple", I wanna have a text that will slide within a defined ...
Oleg G.'s user avatar
  • 580
8 votes
1 answer
2k views

How to animate dynamic List sorting with SwiftUI and CoreData (@FetchRequest)

I have a list that displays a CoreData FetchRequest, and I have a Picker that changes how the list is sorted. The current way I implemented this looks like: struct ParentView: View { enum ...
Dovizu's user avatar
  • 413
7 votes
1 answer
10k views

SwiftUI animation not working using animation(_:value:)

In SwiftUI, I've managed to make a Button animate right when the view is first drawn to the screen, using the animation(_:) modifier, that was deprecated in macOS 12. I've tried to replace this with ...
Dan's user avatar
  • 314
7 votes
2 answers
2k views

SwiftUI - how to override nested offset/position animations?

Consider this simple example: struct TestView: View { @State private var enabled = false var body: some View { Circle() .foregroundColor(.red) .overlay( ...
roozbubu's user avatar
  • 1,146
7 votes
2 answers
3k views

SwiftUI Confetti Animation

Note: I solved the issue. If you are interested in the animation, I created a package with SPM and is available on https://github.com/simibac/ConfettiSwiftUI So I am trying to create a confetti ...
simibac's user avatar
  • 8,090
6 votes
3 answers
4k views

SwiftUI Animation from screen bottom not working properly

I'm trying to create an animation of a View coming into the screen from the bottom. But in the very first time it only appears on screen without any animation and then it starts work properly. This is ...
Sebastian's user avatar
  • 6,314
6 votes
0 answers
258 views

macOS NavigationStack use push and pop animation

how to set the Push / Pop animation in macOS for a NavigationStack ? as currently there is no animation and i want to push / pop the controller sliding right (sliding left), similar to AppStore app ...
Peter Lapisu's user avatar
  • 20.5k
6 votes
0 answers
1k views

SwiftUI: Repeat animation forever with delay at the end, without autoreverse

I want to repeat an animation forever, without it to autoreverse, and with a delay/pause between the repetitions after the animation played. I know there is a .delay() modifier, but it delays the ...
ixany's user avatar
  • 5,773
6 votes
0 answers
834 views

SwiftUI Asymmetric Transition delay is not working

I am trying to create an animation for presenting and dismissing a group of objects. I have: if self.showSignInButtons { Group { Button(action: {}) { ... } HStack { ... } ...
user avatar
5 votes
2 answers
2k views

How to clip a view while using a SwiftUI .move transition / animation

I'm trying to animate in a view and make it appear as if it's a sort of drawer opening from another view. This is all fine except if the first view is not opaque. It appears that you can see the ...
LLooggaann's user avatar
5 votes
1 answer
761 views

Dynamic transitions in SwiftUI

I want to be able to use a different transition depending on the state transition. For example, if I go from .one => .three, I want to fade out ViewOne on removal. If I go from .one => .two, I ...
Russ d'Sa's user avatar
  • 103
5 votes
1 answer
616 views

Interrupting a SwiftUI animation with a drag gesture

Apple has made it easier than ever this year to smoothly animate a view after performing a drag gesture, by automatically using the final velocity of the drag gesture as the initial velocity of the ...
Tim Vermeulen's user avatar
5 votes
0 answers
277 views

How to know when SwiftUI presentation has finished?

I want to know when my SwiftUI view has finished it's transition/animation in order to safely present additional views/modals. Example: I am in View A showing Sheet A. Within Sheet A I tap a button ...
Haensl's user avatar
  • 415
5 votes
0 answers
2k views

SwiftUI Transitions have different implementation?

I have been testing how transitions work based on SwiftUI-labs but I found that transitions should not all be implemented in the same way. Based on the previous article: Note that since XCode 11.2, ...
Aнгел's user avatar
  • 1,399
4 votes
1 answer
4k views

New NavigationStack in SwiftUI transition, how to change from the default slide to custom or appear?

I have NavigationStack with its own navigation links, for iOS16 development. How to change the default slide transition to appear or a custom transition? Also do you apply the transition on the ...
Pro Girl's user avatar
  • 882
4 votes
1 answer
970 views

SwiftUI Chaning Animations

I am trying to chain two animations in SwiftUI. However, the first animation does not animate when pressing the button. I found this approach of chaining animations here: Chaining animations in ...
simibac's user avatar
  • 8,090
4 votes
4 answers
1k views

How can I customise the Animation of an Angle change in SwiftUI

I have an app that shows a bunch of people who each have an origin and angle. struct Location { var centre:CGPoint var facing:Angle } SwiftUI magically and automatically does a lot of the ...
Confused Vorlon's user avatar
4 votes
1 answer
1k views

Animation transition of one gradient to another SwiftUI

I was trying to change the gradient of a background depending on the value of a state value which should be possible, and it is. However, I wanted to animate this change of gradient/background (as you ...
Evan's user avatar
  • 1,980
4 votes
1 answer
1k views

Why SwiftUI-transition does not work as expected when I use it in UIHostingController?

I'm trying to get a nice transition for a view that needs to display date. I give an ID to the view so that SwiftUI knows that it's a new label and animates it with transition. Here's the condensed ...
muvaaa's user avatar
  • 500
4 votes
1 answer
3k views

How to animate hideable views with SwiftUI?

I'm trying out SwiftUI, and while I've found many of its features very elegant, I've had trouble with animations and transitions. Currently, I have something like if shouldShowText { Text(str)....
Etan Ossip's user avatar
4 votes
0 answers
763 views

SwiftUI: LazyVGrid not refreshing while scrolling

I have a LazyVGrid that displays search results, as I type characters in the search field, I perform CoreData fetch requests and update a @Published property. Problem: LazyVGrid updates results as ...
Kuringan's user avatar
  • 147
4 votes
0 answers
888 views

Chaining SwiftUI withAnimation delays - only last animation displayed unless the object is mid-animation where all animations are displayed

It appears that in another question, someone gave a solution that you could chain withAnimations together. It makes sense to me so I tried it and it almost works. While the object is not in motion, ...
Abrakebabra's user avatar
3 votes
1 answer
1k views

Prevent SwiftUI animation from overriding nested withAnimation block

I have a screen with a draggable component (the "Springy" text) that springs back when released with a very prominent spring animation. There is some text that comes in asynchronously (in ...
gohnjanotis's user avatar
  • 7,115
3 votes
3 answers
3k views

SwiftUI Matched Geometry Effect not working with multiple ForEach's

I am basically trying to recreate the photos app. In doing so, matched geometry effect should be the best way to recreate the animation that is used in the photos app when you click on an image/close ...
Trevor's user avatar
  • 763
3 votes
1 answer
455 views

SwiftUI Circle View animation glitch

import SwiftUI struct CircularProgressView: View { @Binding var progress: Float private let strokeStyle = StrokeStyle(lineWidth: 30.0, lineCap: .round, lineJoin: .round) private let ...
GuilhE's user avatar
  • 11.8k
3 votes
3 answers
3k views

SwiftUI: Textfield shake animation when input is not valid

I want to create a shake animation when the User presses the "save"-button and the input is not valid. My first approach is this (to simplify I removed the modifiers and not for this case ...
kirkyoyx's user avatar
  • 343
3 votes
1 answer
4k views

SwiftUI - How to limit the scope of animation to only the onAppear Transition

I'm new to SwiftUI and working through some sample projects to get the hang of it and I'm getting stuck on limiting the scope of the animation I set for the .transition for an AnimationModifier so it ...
got2jam's user avatar
  • 545
3 votes
1 answer
4k views

Understanding scaleEffect in SwiftUI

The following code animates the size of an image as soon as it loads, it animates it from half of its size to its full size, but there is something I don't fully understand about the parameters in ...
fs_tigre's user avatar
  • 11k
3 votes
2 answers
2k views

SwiftUI Transitions of Conditional Child Views

I'm trying to understand and experiment with swiftUI view transitions and could use some insight into why the following does not work the way I expect: struct ContentView: View { @State private var ...
orion's user avatar
  • 374
3 votes
1 answer
830 views

How to keep the same identity for transition animation in SwiftUI

I'm trying to achieve a smooth transition between 2 states of a SwiftUI view. The following code works great, when the offset changes, SwiftUI interpret that as 2 states of the same view (same ...
Damien's user avatar
  • 3,362
3 votes
3 answers
3k views

Disable SwiftUI frame animation on appear

The Goal Let's say I have a List or a LazyVGrid that displays multiple items nested inside a ScrollView. I use a ForEach view to generate the individual item views: ForEach(items) { item in ...
Mischa's user avatar
  • 16.5k
3 votes
3 answers
2k views

How to animate a view in a circular motion using its real-time position coordinates?

I'm currently working on a SwiftUI project, and in order to detect intersections/collisions, I need real-time coordinates, which SwiftUI animations cannot offer. After doing some research, I came ...
PGCodes's user avatar
  • 33
3 votes
1 answer
2k views

Delay SwiftUI combined transitions

With the following code, the intention is to have the transition fading in (opacity) and shifting downwards (offset) at the same time but with a delay of .3 seconds. With this one only the opacity ...
Leo's user avatar
  • 1,690
3 votes
1 answer
120 views

how can I get my Child view to respect the Parent's animation, even when it has its own Child animation?

I have a view that transitions in from the bottom. It's a ZStack, so it has a Child View as well. struct ContentView: View { @State private var presentParent = false var body: some View { ...
ZoydWheeler's user avatar
3 votes
1 answer
148 views

SwiftUI animation issue

I'm creating a flashcard view for language education. The first iteration consisted of flipping cards to front and back. The second iteration consisted of an addition of a swipe-based interface. The ...
kendall.tubbs's user avatar
3 votes
0 answers
67 views

Offset modifier not working when used inside a scoped animation in SwiftUI

The target view has .opacity() and .offset() modifiers in a scoped animation (iOS 17): Text("Hello, world!") .animation(.default) { $0 .opacity(animate ? 1 : 0.2) ...
clns's user avatar
  • 2,190
3 votes
0 answers
1k views

SiwftUI nested buttons, child tap triggers parent animation

I have been looking around but couldn't find the solution so lets hope someone can help me. I have a ScrollView with a LazyVStack in it. Then I have a list of 'cells'. Simplified it looks something ...
Saren Inden's user avatar
  • 3,620
3 votes
1 answer
210 views

SwiftUI Animation onLongPressGesture(minimumDuration: 0.5) automatically starts

I've created a circular button which I specified to show scale animation on .onLongPressGesture(minimumDuration: 0.5) the code is bellow: struct PlayerTouch: View { @State private var ...
Azhman Adam's user avatar
2 votes
1 answer
642 views

How to make this typewriter animation smoother and less blurry?

I'm creating this animation and would like to know if there is a way to make it more enjoyable. here is the code: import SwiftUI struct TypewriterView: View { let text: String @State private ...
Sebastian's user avatar
  • 6,314
2 votes
1 answer
691 views

Animate a button's text and position at the same time in SwiftUI

I have a very simple view that only shows a Text, a Shape, and a Button stacked vertically in a ScrollView. The Shape is a Capsule and is conditionally shown only when showCapsule is true. struct ...
Mischa's user avatar
  • 16.5k
2 votes
1 answer
8k views

Fade-in/out animation with a boolean flag

I am trying to implement a simple "tap to toggle the visibility of the UI" in SwiftUI with fade in/out animation. The following code animates the fade-in effect of the Text element as I ...
Satoshi Nakajima's user avatar
2 votes
1 answer
40 views

Use matchedGeometryEffect to create 'slide' effect for border

I'm trying to create a custom 'tab' selection control with a horizontal row of options and the user can select one of N number of options. The 'selected' option will have a 'border' around it. Here's ...
Z S's user avatar
  • 7,197
2 votes
2 answers
233 views

Conditionally setting two different transitions on the same View

Good day! I have two buttons, one with X and one that says Cancel. Depending on which button I press, I want the X button to have a different transition. When pressing X: I want the removal of the X ...
victorgson's user avatar
2 votes
2 answers
311 views

How do I get the background in swiftui to scale to fit the whole screen

I'm still pretty new to swift UI, almost finished a project however no matter what I try I cannot get the background to take up the whole screen space, with the code below it still has a white border ...
molly0404's user avatar
2 votes
2 answers
824 views

Present sheet with a TextField and its keyboard in a single animation?

I'm building a SwiftUI to-do app. You tap an Add button that pulls up a partial-height sheet where you can enter and save a new to-do. The Add sheet's input (TextField) should be focused when the ...
Dave Feldman's user avatar

1
2 3 4 5 6