To fix a section of a SwiftUI view in place while being animated within an NSWindow, you can wrap the fixed section within a separate SwiftUI view and use the .fixedSize()
modifier to keep it fixed in place.
Here's an example of how you can achieve this:
import SwiftUI
struct ContentView: View {
@State private var isAnimating = false
var body: some View {
VStack {
// Separated fixed view
FixedView()
.fixedSize()
// Animating view
Circle()
.fill(Color.blue)
.frame(width: 100, height: 100)
.offset(x: isAnimating ? 100 : 0, y: 0)
.animation(.easeInOut(duration: 1))
Spacer()
}
.padding()
}
}
struct FixedView: View {
var body: some View {
Text("Fixed View")
.font(.largeTitle)
.fontWeight(.bold)
.padding()
.background(Color.gray)
}
}
In this example, the FixedView
is wrapped within a separate view and the .fixedSize()
modifier is applied to it to keep it fixed in place. The animating view, Circle
, is then placed below the fixed view and animated using the .animation()
modifier.
When you run the code, the FixedView
will remain fixed in place while the Circle
animates horizontally across the screen.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-22 03:03:45 +0000
Seen: 10 times
Last updated: May 22 '23
What is the process to add a radio button with a check mark on a TableView cell using Swift?
Can you develop a "done" button for RxPickerViewAttributedStringAdapter?
When printing from WKWebView in Swift, the background is not taken into account.
How can one ensure that sub-classes have uniform method parameters in TypeScript?
How can the calculation of matrix determinant be performed using CUDA?
How can code repetition be prevented when using (box)plot functions?