Showing and hiding views with transitions in swiftui [closed] - swift

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.

Related

How to design custom drop down menu like android in swiftui? [closed]

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")
}
}
}

Aligning element in up right corner in SwiftUI [closed]

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 last month.
This post was edited and submitted for review last month and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I wanted to ask how to make this navigation button(link) to be in the right up corner?
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: NoteView(), label: {
Text("+")
.bold()
.frame(width: 30, height: 30)
.background(Color.black)
.foregroundColor(.white)
.cornerRadius(10)
})
}
}
}
I tried using ZStack, but it didn't work. I imagine it can be done using spacer, but don't figure out how
To align it in the upper right corner, use a combination of both a VStack and an HStack, with spacers.
Here's how this could be done:
VStack {
HStack {
Spacer() // PUSHES CONTENT TO THE RIGHT
Text("+")
}
Spacer() // PUSHES CONTENT UPWARDS
}
Or...
HStack {
Spacer() // PUSHES CONTENT RIGHT
VStack {
Text("+")
Spacer() // PUSHED CONTENT UP
}
}

How do I implement a loading animation with SwiftUI? [closed]

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!")
}
}
}

How to add a Button below a List in SwiftUI? [closed]

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()
}
}

How to use the NavigationView and NavigationLink [closed]

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