swiftui

Animated view floats into place weirdly SwiftUI

一个人想着一个人 提交于 2021-02-10 16:20:36
问题 So I have a circular progress bar that is declared like this struct ProgressBar: View { var progress: CGFloat var body: some View { let gradient = LinearGradient(...) ZStack { Circle() .stroke(lineWidth: 25) .opacity(0.3) .foregroundColor(Color.secondary) Circle() .trim(from: 0.0, to: CGFloat(min(self.progress, 1.0))) .stroke(gradient ,style: StrokeStyle(lineWidth: 25.0, lineCap: .round, lineJoin: .round)) .rotationEffect(Angle(degrees: 270.0)) .animation(.linear) } } } The variable progress

First item in a List is always selected

坚强是说给别人听的谎言 提交于 2021-02-10 16:10:51
问题 I have a list of items, I want to make it possible to navigate to the details view. However, the first element in the list is always passed to this view, what could be the problem? struct ContentView: View { var array: [Object] = [Object(id: .init(),property: 1),Object(id: .init(),property: 2),Object(id: .init(),property: 3)] @State var showAlert = false @State var showDetailsView = false var body: some View { NavigationView{ List{ ForEach(array){ item in VStack{ Text(String(item.property)) }

First item in a List is always selected

断了今生、忘了曾经 提交于 2021-02-10 16:06:45
问题 I have a list of items, I want to make it possible to navigate to the details view. However, the first element in the list is always passed to this view, what could be the problem? struct ContentView: View { var array: [Object] = [Object(id: .init(),property: 1),Object(id: .init(),property: 2),Object(id: .init(),property: 3)] @State var showAlert = false @State var showDetailsView = false var body: some View { NavigationView{ List{ ForEach(array){ item in VStack{ Text(String(item.property)) }

How can I pop a navigation view and return to the previous view rather than the root view SwiftUI?

心不动则不痛 提交于 2021-02-10 15:44:09
问题 I have a ContentView that is the root view that navigates to a DetailView. The DetailView has a navbaritem that navigates to Help2 view. I want to click a button to dismiss the Help2 view and return to the DetailView (the view from which Help2 came from). Currently, when I press a button on the Help2 view, it dismisses the view, but it returns me to the root ContentView rather than DetailView . If I navigate to the Help2 view then manually click the back button to navigate to DetailView , it

UIPageViewController stops working after 1 swipe in SwiftUI

≡放荡痞女 提交于 2021-02-10 15:16:13
问题 I was following the Apple tutorial for SwiftUI and under 'Interfacing with UIKit' (https://developer.apple.com/tutorials/swiftui/interfacing-with-uikit) we were made to make a UIPageController. In the tutorial, they used a State property to update the currentPage variable in PageView . I wanted to experiment a little bit and decided that I want to embed the PageView in a different view and have a currentPage property update in that parent view instead. So, naturally, I changed the @State

UIPageViewController stops working after 1 swipe in SwiftUI

时间秒杀一切 提交于 2021-02-10 15:15:25
问题 I was following the Apple tutorial for SwiftUI and under 'Interfacing with UIKit' (https://developer.apple.com/tutorials/swiftui/interfacing-with-uikit) we were made to make a UIPageController. In the tutorial, they used a State property to update the currentPage variable in PageView . I wanted to experiment a little bit and decided that I want to embed the PageView in a different view and have a currentPage property update in that parent view instead. So, naturally, I changed the @State

How to display a text view in swift UI if the variable isn't nil?

早过忘川 提交于 2021-02-10 14:43:49
问题 This is basically my code I have: var myString: String? var body: some View { NavigationView { if myString != nil { CustomView(text: myString ?? "") } } } If I try without adding the ?? "" part, it doesn't work, says Value of optional type 'String?' must be unwrapped to a value of type 'String' . If I add it in as shown above, it seems to work, but why do I need to have a default empty string value if that's never going to be the case? (Since it will only reach that code if myString is not

How to display a text view in swift UI if the variable isn't nil?

偶尔善良 提交于 2021-02-10 14:42:32
问题 This is basically my code I have: var myString: String? var body: some View { NavigationView { if myString != nil { CustomView(text: myString ?? "") } } } If I try without adding the ?? "" part, it doesn't work, says Value of optional type 'String?' must be unwrapped to a value of type 'String' . If I add it in as shown above, it seems to work, but why do I need to have a default empty string value if that's never going to be the case? (Since it will only reach that code if myString is not

SwiftUI | Picker - Change selected row color

人盡茶涼 提交于 2021-02-10 14:34:05
问题 I want to change the color of the selected row. As you may see, by default it has this light gray color. I have no idea how to do that since I have found no way to access this row at all. Is there any way to do that? Demo code: struct ContentView: View { var data = Array(0...20).map { "\($0)" } @State private var selected = 0 var body: some View { VStack { Picker("", selection: $selected) { ForEach(0 ..< data.count) { Text(data[$0]) } } } } } A UIKit answer would also be welcomed since I have

SwiftUI | Picker - Change selected row color

巧了我就是萌 提交于 2021-02-10 14:33:09
问题 I want to change the color of the selected row. As you may see, by default it has this light gray color. I have no idea how to do that since I have found no way to access this row at all. Is there any way to do that? Demo code: struct ContentView: View { var data = Array(0...20).map { "\($0)" } @State private var selected = 0 var body: some View { VStack { Picker("", selection: $selected) { ForEach(0 ..< data.count) { Text(data[$0]) } } } } } A UIKit answer would also be welcomed since I have