Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I already have an animation made in AfterEffects that I think Lottie can turn into a format I can use for my app. What I am wondering is how can I make the app start performing this animation when it is opened until the app is done loading?
Simply show the animation view instead of your content view while it's loading
example:
struct ContentView: View {
#State var isLoading = true
var body: some View {
VStack {
if isLoading {
LoadingView()
} else {
DoneLoadingView()
}
}.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
isLoading = false
}
}
}
}
struct LoadingView: View {
var body: some View {
ProgressView()
}
}
struct DoneLoadingView: View {
var body: some View {
VStack {
Text("Hello, world!")
}
}
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 13 days ago.
The community is reviewing whether to reopen this question as of 13 days ago.
Improve this question
I want to show custom drop down menu very attractive view but it does not work when I write the code as I want.
This is drop down menu approach but does not work can anyone tell the solution in any others way also.
struct DropDownList:View{
var body: some View{
Menu(content: {
HStack{
Image(systemName: "eye")
Text("Eye Clinic")
}
HStack{
Image("neuro")
Text("Neuro Hospital")
}
}, label: {
Text("Hospitals")
})
}
}
Your question isn't clear, but the menu you show in the image can be created as follows:
struct ContentView: View {
var body: some View {
HStack {
Text("Something")
DropDownList()
}
}
}
struct DropDownList:View {
var body: some View {
Menu {
Button {
} label: {
Label("Edit", systemImage: "square.and.pencil")
}
Button {
} label: {
Label("Delete", systemImage: "trash")
}
} label: {
Image(systemName: "ellipsis")
}
}
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
i try to make 'showing and hiding views with transitions' in Animations (with swiftUI) ;
import SwiftUI
struct ContentView: View {
#State private var isShowingRed = false
var body: some View {
VStack {
Button("tap me") {
withAnimation {
isShowingRed.toggle()
}
}
if isShowingRed {
Rectangle()
.fill(.red)
.frame(width: 200, height: 200)
transition(.asymmetric(insertion: .scale, removal: .opacity))
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
but got error like ;
An unknown crash has occurred, check back for more information. How to fix that erro,any idea?
Thanks.
It looks like you forgot to put a . before transition(.asymmetric(insertion: .scale, removal: .opacity)).
That might be why.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have this class
class StoreWrapper:ObservableObject {
#Published var displaySpinner: Bool = true
}
and I am trying to use this var to control the visibility of a spinner on ContentView, like this
CONTENT VIEW
private var storeWrapper = StoreWrapper.sharedInstance
var body: some View {
if storeWrapper.displaySpinner {
Spinner()
}
I can change the displaySpinner variable to false and the spinner will not hide.
But if I do this:
CONTENT VIEW
#State var displaySpinner = true
var body: some View {
if displaySpinner {
Spinner()
}
and change displaySpinner to false, the spinner will hide.
Any ideas?
Try using #StateObject to watch the property. Here's the example I set up to test it.
struct ContentView: View {
#StateObject var displayWrapper = StoreWrapper()
var body: some View {
VStack {
if displayWrapper.displaySpinner {
Text("I'm spinning")
} else {
Text("No spins here.")
}
Button("Toggle Spinner") {
displayWrapper.displaySpinner.toggle()
}
}
}
}
You need to let the View know that the storeWrapper is an observed object.
This line:
private var storeWrapper = StoreWrapper.sharedInstance
should be:
#ObservedObject private var storeWrapper = StoreWrapper.sharedInstance
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
how can I add a Button in SwiftUI below a List so that it looks like in the Note app:
I tried it with a Stack but this did not work.
Here is simple demo:
struct DemoListWithButton: View {
var body: some View {
NavigationView {
VStack(alignment: .trailing) {
List(0..<100) { i in
Text("Item \(i)")
}
.navigationBarTitle("Title")
Button("Button") {}
.padding()
}
}
}
}
struct DemoListWithButton_Previews: PreviewProvider {
static var previews: some View {
DemoListWithButton()
}
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am setting NavigationLink for Item,but not work with image disappeared.
struct Items: View {
var landmarks: [Landmark]
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(landmarks) { landmark in
//加了这个导航就看不到图片了,CategoryHome 也不显示图片,
//NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
Item(landmark: landmark)
//}
}
}
}
}
}
You have to embed your Scrollview into a NavigationView or it will not work
struct Items: View {
var landmarks: [Landmark]
var body: some View {
NavigationView {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(landmarks) { landmark in
//加了这个导航就看不到图片了,CategoryHome 也不显示图片,
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
Item(landmark: landmark)
}
}
}
}
}
}
}
Here is the apple tutorial for creating navigation is SwiftUI