CodexBloom - Programming Q&A Platform

Unexpected UI lag when using Core Animation with SwiftUI on iOS 17

๐Ÿ‘€ Views: 88 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-12
swiftui core-animation ios-17 performance Swift

I'm refactoring my project and I've searched everywhere and can't find a clear answer... I'm working on a project and hit a roadblock. I'm experiencing significant UI lag when animating a SwiftUI view that uses Core Animation for transitions. Specifically, I'm creating a view that transitions between two states with a smooth scaling effect. However, on devices running iOS 17, the animation stutters and impacts the overall performance. Hereโ€™s a simplified version of my code: ```swift struct ScalingView: View { @State private var isScaled = false var body: some View { Circle() .fill(Color.blue) .frame(width: isScaled ? 200 : 100, height: isScaled ? 200 : 100) .onTapGesture { withAnimation(.easeInOut(duration: 0.5)) { isScaled.toggle() } } } } ``` I've tried using the `.transaction()` modifier to adjust the animation settings and also disabled implicit animations to see if that helps: ```swift .onAppear { withAnimation(.none) { // Some setup code here } } ``` Despite these efforts, the UI still lags noticeably. Iโ€™ve also checked for any heavy calculations in the main thread and ensured that all UI updates are performed on the main thread. The issue seems to occur specifically when interacting with the animation and SwiftUIโ€™s layout system. Additionally, I've tried testing it on both a physical device (iPhone 13) and the simulator, and the issue persists in both cases. I'm using Xcode 15.0 with SwiftUI 4.0. Is there a known issue with Core Animation and SwiftUI interactions in iOS 17 that could cause this lag, or are there recommended best practices to enhance performance during such animations? My development environment is macOS. Any ideas what could be causing this? I'm working on a service that needs to handle this. I'd really appreciate any guidance on this. I'm working in a macOS environment. Any ideas what could be causing this? The stack includes Swift and several other technologies. Could someone point me to the right documentation?