swiftui

Unwanted SplitView on modal view displayed on iPad

时光怂恿深爱的人放手 提交于 2021-02-11 05:57:27
问题 Testing my first SwiftUI app on iPad, I discovered that the modal views I display from my ContentView are displayed as Split views on the iPad, with the UI being truncated on the master side and the detail side is empty. I did check both posts here : Unwanted SplitView and, What's the equality of the UISplitView controller But their solution of applying the .navigationViewStyle(StackNavigationViewStyle) to the NavigationView does not work for me : I display my modals through user input (tap

.toggle() function on bool does not call didSet. Is this a bug?

懵懂的女人 提交于 2021-02-11 05:10:13
问题 I have a @State Bool variable with didSet on it. I want to do something when the variable change therefore I have tried to use didSet. The problem is when I use the .toggle() function to toggle the state of the bool, didSet is not called. Take this code for example: import SwiftUI struct SwiftUIView: View { @State var testBool = false { didSet { print("set") } } var body: some View { VStack { Button(action: { self.testBool.toggle() }) { Text("Toggle with .toggle()") } Button(action: { if self

After appending element to array it should show more elements

白昼怎懂夜的黑 提交于 2021-02-11 05:09:18
问题 This is how it looks before and after.. I have a ForEach Loop, and when I click on the card, it appends a new element to the array and then IT SHOULD SHOW 2 CARDS. But there is still one card. (but I appended the new card element) So what should I do? struct TimelineFromUserView: View { var card: [Card] = cardData var body: some View { VStack { HStack { Text("History").bold() .font(.largeTitle) .padding(.top, 20) .padding(.leading, 20) Spacer() } Divider() ScrollView(.vertical,

After appending element to array it should show more elements

家住魔仙堡 提交于 2021-02-11 05:08:58
问题 This is how it looks before and after.. I have a ForEach Loop, and when I click on the card, it appends a new element to the array and then IT SHOULD SHOW 2 CARDS. But there is still one card. (but I appended the new card element) So what should I do? struct TimelineFromUserView: View { var card: [Card] = cardData var body: some View { VStack { HStack { Text("History").bold() .font(.largeTitle) .padding(.top, 20) .padding(.leading, 20) Spacer() } Divider() ScrollView(.vertical,

After appending element to array it should show more elements

无人久伴 提交于 2021-02-11 05:07:23
问题 This is how it looks before and after.. I have a ForEach Loop, and when I click on the card, it appends a new element to the array and then IT SHOULD SHOW 2 CARDS. But there is still one card. (but I appended the new card element) So what should I do? struct TimelineFromUserView: View { var card: [Card] = cardData var body: some View { VStack { HStack { Text("History").bold() .font(.largeTitle) .padding(.top, 20) .padding(.leading, 20) Spacer() } Divider() ScrollView(.vertical,

SwiftUI NavigationLink in list

旧时模样 提交于 2021-02-11 04:33:29
问题 I tried to do a list which have image and a navigation link inside. In iOS 14.1 everything work fine but after I update my iOS to 14.2, something break. In the list while the user click the big image there will be a action sheet pop out, while the user click a systemImage it will trigger a navigation link. However, when I update to iOS 14.2, no matter what I clicked, it will trigger the NavigationLink. Can someone explain to me why will this happened and how to solve? Here is the sample code

SwiftUI NavigationLink in list

喜夏-厌秋 提交于 2021-02-11 04:32:07
问题 I tried to do a list which have image and a navigation link inside. In iOS 14.1 everything work fine but after I update my iOS to 14.2, something break. In the list while the user click the big image there will be a action sheet pop out, while the user click a systemImage it will trigger a navigation link. However, when I update to iOS 14.2, no matter what I clicked, it will trigger the NavigationLink. Can someone explain to me why will this happened and how to solve? Here is the sample code

SwiftUI - Determining Current Device and Orientation

感情迁移 提交于 2021-02-11 04:31:16
问题 I am trying to detect when the device is on iPad and in Portrait. Currently I use the UIDevice API in UIKit and use an environment object to watch changes. I use the solution found here - Determining Current Device and Orientation. However the orientationInfo.orientation is initially always equal to .portrait until rotated into portrait and then back to landscape. So when doing the following to display the FABView struct HomeView: View { @EnvironmentObject var orientationInfo: OrientationInfo

SwiftUI NavigationLink in list

痞子三分冷 提交于 2021-02-11 04:30:15
问题 I tried to do a list which have image and a navigation link inside. In iOS 14.1 everything work fine but after I update my iOS to 14.2, something break. In the list while the user click the big image there will be a action sheet pop out, while the user click a systemImage it will trigger a navigation link. However, when I update to iOS 14.2, no matter what I clicked, it will trigger the NavigationLink. Can someone explain to me why will this happened and how to solve? Here is the sample code

How to pause an animation in SwiftUI?

天大地大妈咪最大 提交于 2021-02-10 20:31:09
问题 I don't know how to stop withAnimation(_:) method after starting it. I am writing my first app with SwiftUI and I want to create a progress circle, which will be controlled with buttons by user - start button, which will start animation, where circle will be unfilled at the end and stop button will have to save actual state of the fill point and stop the animation. My main view: struct MainView: View { @State private var fillPoint = 1.0 @State private var animationDuration = 10.0 private var