swiftui

SwiftUI horizontal alignment from center to the right

谁都会走 提交于 2021-01-29 11:42:50
问题 I am trying to align a dynamic collection (ie of varying count) of views to the right of a centered view, without moving the center view from its original, center position. For example, the center view is Text("12") and the views to the right are [Text("+3"), Text("+10"), Text("-1")] so I want the views to the right of 12 be displayed to its right, while 12 is centered horizontally on the screen: | 12 +3 +10 -1 | If I try using an HStack the 12 will move away from center. Is there a view

How to access goBack and goForward via UIViewRepresentable

泪湿孤枕 提交于 2021-01-29 11:31:45
问题 I have added a WKwebview in SwiftUI via UIVewRepresentable. I am having difficulties getting some buttons to make the web view go back and go forward. Below is the two classes I have made but I am not even getting print to work ( maybe a bug? ). import SwiftUI import WebKit struct Webview : UIViewRepresentable { let request: URLRequest func makeUIView(context: Context) -> WKWebView { return WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { uiView.load(request) } func

problems in displaying different titles in navigation bar

这一生的挚爱 提交于 2021-01-29 11:31:32
问题 in my code I have this: var body: some View { NavigationView { VStack(spacing: 0) { ScrollView(.vertical, showsIndicators: false) { VStack(spacing: 18) { ScrollView(.horizontal, showsIndicators: false){ HStack(spacing: 20){ Text("teste") .frame(height: 180) .frame(width: 330) .background(Color.blue) .cornerRadius(15) Text("teste") .frame(height: 180) .frame(width: 330) .background(Color.green) .cornerRadius(15) Text("teste") .frame(height: 180) .frame(width: 330) .background(Color.pink)

How to set NavigationView default value?

本小妞迷上赌 提交于 2021-01-29 10:13:28
问题 I have the following code: import SwiftUI struct DetailView: View { let text: String var body: some View { Text(text) .frame(maxWidth: .infinity, maxHeight: .infinity) } } struct ContentView: View { private let names = ["One", "Two", "Three"] @State private var selection: String? = "One" var body: some View { NavigationView { List(selection: $selection) { ForEach(names, id: \.self) { name in NavigationLink(destination: DetailView(text: name)) { Text(name) } } } DetailView(text: "Make a

SwiftUI Grid Images Can't be Tapped to Show DetailView

北战南征 提交于 2021-01-29 09:54:02
问题 I'm trying to create a collection view in SwiftUI. I can create the grid (of images in this case) but I have not found a way to click an image and transition to another view - neither a modal nor a full view. I am storing the images in CoreData and am using a method from Paul Hudson to break the images into rows: https://www.hackingwithswift.com/example-code/language/how-to-split-an-array-into-chunks This code does allow transitions, but with a single click it cycles through each of the

SwiftUI Conditional View Transitions are not working

孤人 提交于 2021-01-29 09:42:47
问题 Consider the following code: class ApplicationHostingView: ObservableObject { @Published var value: Bool } struct ApplicationHostingView: View { // view model env obj var body: some View { Group { if applicationHostingViewModel.value { LoginView() .transition(.move(edge: .leading)) // <<<< Transition for Login View } else { IntroView() } } } } struct IntroView: View { // view model env obj var body: some View { Button(action: { applicationHostingViewModel.value = true }) { Text("Continue") }

Use of unresolved identifier 'Map' SwiftUI

放肆的年华 提交于 2021-01-29 09:18:04
问题 I am following the official tutorial for SwiftUI and have run into the error message 'Use of unresolved identifier 'Map'. Even when I copy and and paste the code from the tutorial, it is still giving me the error. I have looked at a few solutions for similar issues and can't seem to find anything that will work. Code below. import SwiftUI import MapKit struct MapView: View { @State private var region = MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 34.011_286, longitude: -116

Why does MagnificationGesture only update the state once in SwiftUI?

限于喜欢 提交于 2021-01-29 09:16:57
问题 I wish to have the following view respond to the magnification gestures, but it only works the first time. The view can be magnified as expected, but after the view is released, subsequent touches do not trigger the gesture. Is there a way to have the gesture work continuously? struct Card: View { @State var magScale: CGFloat = 1 var magnification: some Gesture { MagnificationGesture().onChanged { gesture in magScale = gesture } } var body: some View { Rectangle() .frame(width: 200, height:

SwiftUI: How to find the height of an image and use it to set the size of a frame

对着背影说爱祢 提交于 2021-01-29 08:34:04
问题 So I've been trying to figure out how to find the height of an image in SwiftUI for a while now with no success. Essentially I have portrait/landscape images, which the portrait ones I want to display at about 600 pt tall, whereas the landscape images I want to display so the width of the image is used, so the height is whatever. That being said, I'm wanting it inside of a GeometryReader, as the offset I am using uses it so that when you scroll down, the image doesn't scroll, but if you

LazyVStack scrolling stops animations

[亡魂溺海] 提交于 2021-01-29 07:51:01
问题 This code lists 100 rows with refresh icon animations. When using a LazyVStack instead of a VStack , after scrolling down to the bottom of this list all the animations stop, including those at the top of the list once you scroll back. No such issues with a VStack . Any ideas as to why this is happening and is there a workaround? Using Xcode 12.0.1, iOS 14, Swift 5 struct RefreshingList : View { @State var isAnimating = false var body: some View { ScrollView { LazyVStack { // <- change to