Post

Replies

Boosts

Views

Activity

onTapGesture conflicts with button
I want to perform some code when the form is tapped. However the button in the form is affected by the onTapGesture either. I want the button tapped to execute the action block, not the onTapGesture block. How should I do? Thanks in advance. struct TextFieldPopupView: View {     @State private var text = ""     @State private var isON = false     var body: some View {         Form{             Text("Hello")             TextField("Hello", text: $text) .textFieldStyle(RoundedBorderTextFieldStyle())             Button(action: {                 print("Button")             }, label: {Text("Button")})             Toggle(isOn: $isON, label: {                 Text("Toggle")             })         }         .onTapGesture {             print("Form")         }     } }
2
1
6.3k
Jun ’21
A weird problem of LazyVGrid layout
I wrote some code using LazyVGrid. struct LazyVStackTestView: View {     let columnGridItem = Array(repeating: GridItem(), count: 3)     var body: some View {         GeometryReader{geo in             HStack{                 Rectangle().frame(maxWidth: 300,maxHeight: 100)                 LazyVGrid(columns: columnGridItem){                     ForEach(1..<13) { btn in                         Image(systemName: "plusminus.circle")                             .resizable()                             .scaledToFit()                             .clipShape(Circle())                     }                 }                 .padding()                 .frame(maxWidth: geo.size.height*0.6, maxHeight: geo.size.height)             }.border(Color.black)             .padding()         }.border(Color.blue)     } } When run it on simulator(iPhone 11) in horizontal orientation, I get a 4rows3columns button pad that is what I want. But when I turn the simulator to vertical orientation and back to horizontal orientation immediately, the button pad becomes 3rows3columns! What had happened? Any help will be appreciated.
2
0
2.8k
Jun ’21
What's the difference between InlinePickerStyle and WheelPickerStyle
struct PickerStyleView: View {     @State private var num  =  0     var body: some View {         Form{             Text("Number")             Picker(String(num), selection: $num, content: {                                  Text("5").tag(5)                 Text("10").tag(10)                 Text("15").tag(15)                 Text("20").tag(20)             })             .pickerStyle(InlinePickerStyle())         }     } } Using InlinePickerStyle() and WheelPickerStyle() seems to be no difference. What does "InlinePickerStyle()" refer to? And which case is "InlinePickerStyle()" suitable for in practice? Any help will be appreciated.
1
0
794
Sep ’21
"onTapGesture" interferes with segmented picker
struct ProblemSegmentTest: View {     @State private var select = 0     var body: some View {         VStack {             Picker("Test", selection: $select) {                 Text("A").tag(0)                 Text("B").tag(1)                 Text("C").tag(2)             }             .pickerStyle(SegmentedPickerStyle())         }         .onTapGesture {             print("test")         }     } } I want to do sth when the picker is taped. However, when I apply ".onTapGesture" to the vstack, the picker's options can't be selected any more. Any help will be appreciated.
5
1
2.0k
Oct ’21
debug problem in Xcode13
struct ContentView: View {     @State private var num = 0          var body: some View {         VStack{         Text(String(num))             .padding()         Button(action: {             num += 1         }, label: {Text("click+1")})         }     } } Question 1: If I run the code above on simulator, I could get the value of "num" on the console by using"po _num". However, if I run the code in previews(by "Debug-Attach to process"), I only get the error"error: :3:1: error: cannot find '_num' in scope" on the console by using"po _num" Xcode 13.2.1 Question 2: I could use "po num"/"po _num" to get the value of "num" with Xcode 12. BUT, only "po _num" works in Xcode13. "po num" will raise the error:" error: Couldn't lookup symbols: Preview2.ContentView.num.getter : Swift.Int" Any help will be appreciated.
0
0
1.3k
Dec ’21
Invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific
I make a toggle to control a textfield in a form. When I run it, I get a piece of warning: invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution What could I do to fix it? What's the harm if it's not fixed( App crashes, or...?). Any help will be appreciated. struct ContentView: View {     @State private var toggle1 = true     @State private var str1 = "..."     var body: some View {         Form{             Section{                 Toggle(isOn: $toggle1, label: {                     Text("Toggle 1")})             }             Section{                     if toggle1{                         HStack{                             Text("Toggle 1")                             TextField("...", text: $str1)                         }                     }             }             .textFieldStyle(RoundedBorderTextFieldStyle())         }     } }
0
1
1.2k
Jan ’22
Scroll two lists synchronously
I have two lists side-by-side. I want to scroll any one of the lists, and the other one can scroll synchronously. Is there any way to achieve the effect? Any help will be appreciated. struct ScrollTwoListsSynchronously: View {     let dataSet = [1,2,3,4,5]     var body: some View {         HStack{             List{                 ForEach(dataSet,id:\.self){data in                     Text(String(data))                 }             }             .listStyle(PlainListStyle())             List{                 ForEach(dataSet,id:\.self){data in                     Text(String(data))                 }             }             .listStyle(PlainListStyle())         }     } }
0
0
530
May ’22
How to auto adjust the height of list row in edit mode?
I have a list. When I click the show button in any of rows, the long text appears and the height of row auto gets taller enough to show all of the long text. However, when the list is in "edit" mode, the height of row can't auto get taller enough to show all of the long text. The long text is truncated. I have to push the list to the top manually and release, then the height of row auto gets taller and the long text can be completely displayed again. Is there any way to achieve the "auto" adjustment effect just the same as the "non-edit" mode? struct ListEditTest: View { @State private var selects: Set<Int> = [] var body: some View { VStack{ EditButton() List(selection: $selects){ ForEach(1..<5){ ItemInList(num: $0) } } .listStyle(PlainListStyle()) } } } struct ItemInList: View{ let num: Int @State private var showDetail = false var body: some View{ HStack{ Text("NO.\(num)") Text("HelloWorld") if showDetail{ Text("TooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWords") Button { showDetail.toggle() } label: { Text("Hide") } }else{ Button { showDetail.toggle() } label: { Text("Show") } } } .buttonStyle(BorderlessButtonStyle()) } }
4
0
2.6k
Jun ’22
Inserted record without option icon in a list can be selected in edit mode
I have a list to show some records. A weird issue will happen as follow steps: --tap "insert" button for some times(eg. 3 times) --swipe a record from right to left to delete it --tap "edit" button to switch to edit mode --tap "insert" button to insert a new record The first 2 records both have a "option button"(a small hollow circle). BUT the last inserted record has no "option button". The list seems like to reuse the view of the deleted record in "non-edit" mode. All of the 3 records can be selected by click. I wonder how to make the inserted record to also have a "option button". struct ListEditModeSubviewUpdateTest: View { @State private var data = [Int]() @State private var editMode = EditMode.inactive @State private var selects = Set<Int>() @State private var base = 0 var body: some View{ VStack{ Button { if editMode.isEditing{ editMode = .inactive }else{ editMode = .active } } label: { Text(editMode.isEditing ? "Done" : "Edit") } Button { base += 1 data.append(base) } label: { Text("Insert") } List(selection: $selects){ ForEach(data, id:\.self){item in Text(String(item)) } .onDelete{ data.remove(atOffsets: $0) } } } .environment(\.editMode, $editMode) } }
0
0
593
Jun ’22
How to prevent the background color from going beyond the safe area when rotating the simulator
I need to use some "uikit view controller" in my swiftui app. I have encapsulate the vc in a representable view. It works well. However, the background color will extend outside of safe area when I rotate the simulator from portrait to landscape and back to portrait. I want the background color always to stay inside safe area. I prototype a sample code to illustrate the issue. struct ContentView: View { var body: some View { ZStack{ Color.gray CustomRepresentation() } } } struct CustomRepresentation: UIViewControllerRepresentable{ func makeUIViewController(context: Context) -> some UIViewController { return UIViewController() } func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { } } If I comment the CustomRepresentation(), the gray color will stay inside the safe area all the time during rotating. So I realize the key point is CustomRepresentation(). But I don't know how to fix it.
0
0
984
Oct ’22
Reload images from PHPickerViewController
I'm writing an app which allow users to pick images from photo library by swiftUI. I wrap PHPickerViewController in representable to achieve the functionality. The benefit is that users don’t need to explicitly authorize my app to select photos. func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) Currently, I get images by picker(::) method above and save images in my app in order to reload images the next time users launch the app without needs to request authorization. Obviously, if the app stores references to the selected images, rather than images themselves, it can prevent from taking up large amounts of space. Is it meaning that I have to prompt to users for requesting authorization to access the library? Is there any approach only to use references and reload images which were selected by users previously from photo library using PHPickerViewController, supporting no need to request authorization.
1
0
1.6k
Nov ’22
Is there any detailed article on "How to use RedactionReasons"
I know I can use .redacted(reason: .placeholder) to make displayed data appear as generic placeholders. But how can I declare a custom RedactionReasons instance and use it? The examples of initializer in documentation seem not to be helpful. Thanks in advance.
Replies
0
Boosts
0
Views
450
Activity
Jun ’21
onTapGesture conflicts with button
I want to perform some code when the form is tapped. However the button in the form is affected by the onTapGesture either. I want the button tapped to execute the action block, not the onTapGesture block. How should I do? Thanks in advance. struct TextFieldPopupView: View {     @State private var text = ""     @State private var isON = false     var body: some View {         Form{             Text("Hello")             TextField("Hello", text: $text) .textFieldStyle(RoundedBorderTextFieldStyle())             Button(action: {                 print("Button")             }, label: {Text("Button")})             Toggle(isOn: $isON, label: {                 Text("Toggle")             })         }         .onTapGesture {             print("Form")         }     } }
Replies
2
Boosts
1
Views
6.3k
Activity
Jun ’21
A weird problem of LazyVGrid layout
I wrote some code using LazyVGrid. struct LazyVStackTestView: View {     let columnGridItem = Array(repeating: GridItem(), count: 3)     var body: some View {         GeometryReader{geo in             HStack{                 Rectangle().frame(maxWidth: 300,maxHeight: 100)                 LazyVGrid(columns: columnGridItem){                     ForEach(1..<13) { btn in                         Image(systemName: "plusminus.circle")                             .resizable()                             .scaledToFit()                             .clipShape(Circle())                     }                 }                 .padding()                 .frame(maxWidth: geo.size.height*0.6, maxHeight: geo.size.height)             }.border(Color.black)             .padding()         }.border(Color.blue)     } } When run it on simulator(iPhone 11) in horizontal orientation, I get a 4rows3columns button pad that is what I want. But when I turn the simulator to vertical orientation and back to horizontal orientation immediately, the button pad becomes 3rows3columns! What had happened? Any help will be appreciated.
Replies
2
Boosts
0
Views
2.8k
Activity
Jun ’21
Change the price of my app
I have an app released in the iOS store which is set to be price tier 1. I want to set it to be free for just next week. After that, the price should be back to price tier1 again. If I tune it in App Store connect. Will it make my app to be in review again, or just take effect immediately? Thanks in advance.
Replies
0
Boosts
0
Views
671
Activity
Jun ’21
some symbols in sf symbol 3 can't be displayed
I downloaded sf symbol3 today. My Xcode is 12.5. When I write a simple code like: Image(systemName: "gearshape") everything is ok. However when the code turns to : Image(systemName: "gearshape.circle") nothing will be displayed. Do I miss anything? Thanks in advance.
Replies
1
Boosts
0
Views
2.2k
Activity
Jun ’21
What's the difference between InlinePickerStyle and WheelPickerStyle
struct PickerStyleView: View {     @State private var num  =  0     var body: some View {         Form{             Text("Number")             Picker(String(num), selection: $num, content: {                                  Text("5").tag(5)                 Text("10").tag(10)                 Text("15").tag(15)                 Text("20").tag(20)             })             .pickerStyle(InlinePickerStyle())         }     } } Using InlinePickerStyle() and WheelPickerStyle() seems to be no difference. What does "InlinePickerStyle()" refer to? And which case is "InlinePickerStyle()" suitable for in practice? Any help will be appreciated.
Replies
1
Boosts
0
Views
794
Activity
Sep ’21
"onTapGesture" interferes with segmented picker
struct ProblemSegmentTest: View {     @State private var select = 0     var body: some View {         VStack {             Picker("Test", selection: $select) {                 Text("A").tag(0)                 Text("B").tag(1)                 Text("C").tag(2)             }             .pickerStyle(SegmentedPickerStyle())         }         .onTapGesture {             print("test")         }     } } I want to do sth when the picker is taped. However, when I apply ".onTapGesture" to the vstack, the picker's options can't be selected any more. Any help will be appreciated.
Replies
5
Boosts
1
Views
2.0k
Activity
Oct ’21
debug problem in Xcode13
struct ContentView: View {     @State private var num = 0          var body: some View {         VStack{         Text(String(num))             .padding()         Button(action: {             num += 1         }, label: {Text("click+1")})         }     } } Question 1: If I run the code above on simulator, I could get the value of "num" on the console by using"po _num". However, if I run the code in previews(by "Debug-Attach to process"), I only get the error"error: :3:1: error: cannot find '_num' in scope" on the console by using"po _num" Xcode 13.2.1 Question 2: I could use "po num"/"po _num" to get the value of "num" with Xcode 12. BUT, only "po _num" works in Xcode13. "po num" will raise the error:" error: Couldn't lookup symbols: Preview2.ContentView.num.getter : Swift.Int" Any help will be appreciated.
Replies
0
Boosts
0
Views
1.3k
Activity
Dec ’21
Invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific
I make a toggle to control a textfield in a form. When I run it, I get a piece of warning: invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution What could I do to fix it? What's the harm if it's not fixed( App crashes, or...?). Any help will be appreciated. struct ContentView: View {     @State private var toggle1 = true     @State private var str1 = "..."     var body: some View {         Form{             Section{                 Toggle(isOn: $toggle1, label: {                     Text("Toggle 1")})             }             Section{                     if toggle1{                         HStack{                             Text("Toggle 1")                             TextField("...", text: $str1)                         }                     }             }             .textFieldStyle(RoundedBorderTextFieldStyle())         }     } }
Replies
0
Boosts
1
Views
1.2k
Activity
Jan ’22
keyboard can't be popped up in live preview mode
In the simulator, everything is ok. However, in live preview mode of canvas, no keyboard pops up when I tap in the textfield. Did I miss anything? Or need more codes in preview?Thanks in advance.
Replies
6
Boosts
0
Views
16k
Activity
Apr ’22
Scroll two lists synchronously
I have two lists side-by-side. I want to scroll any one of the lists, and the other one can scroll synchronously. Is there any way to achieve the effect? Any help will be appreciated. struct ScrollTwoListsSynchronously: View {     let dataSet = [1,2,3,4,5]     var body: some View {         HStack{             List{                 ForEach(dataSet,id:\.self){data in                     Text(String(data))                 }             }             .listStyle(PlainListStyle())             List{                 ForEach(dataSet,id:\.self){data in                     Text(String(data))                 }             }             .listStyle(PlainListStyle())         }     } }
Replies
0
Boosts
0
Views
530
Activity
May ’22
How to auto adjust the height of list row in edit mode?
I have a list. When I click the show button in any of rows, the long text appears and the height of row auto gets taller enough to show all of the long text. However, when the list is in "edit" mode, the height of row can't auto get taller enough to show all of the long text. The long text is truncated. I have to push the list to the top manually and release, then the height of row auto gets taller and the long text can be completely displayed again. Is there any way to achieve the "auto" adjustment effect just the same as the "non-edit" mode? struct ListEditTest: View { @State private var selects: Set<Int> = [] var body: some View { VStack{ EditButton() List(selection: $selects){ ForEach(1..<5){ ItemInList(num: $0) } } .listStyle(PlainListStyle()) } } } struct ItemInList: View{ let num: Int @State private var showDetail = false var body: some View{ HStack{ Text("NO.\(num)") Text("HelloWorld") if showDetail{ Text("TooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWords") Button { showDetail.toggle() } label: { Text("Hide") } }else{ Button { showDetail.toggle() } label: { Text("Show") } } } .buttonStyle(BorderlessButtonStyle()) } }
Replies
4
Boosts
0
Views
2.6k
Activity
Jun ’22
Inserted record without option icon in a list can be selected in edit mode
I have a list to show some records. A weird issue will happen as follow steps: --tap "insert" button for some times(eg. 3 times) --swipe a record from right to left to delete it --tap "edit" button to switch to edit mode --tap "insert" button to insert a new record The first 2 records both have a "option button"(a small hollow circle). BUT the last inserted record has no "option button". The list seems like to reuse the view of the deleted record in "non-edit" mode. All of the 3 records can be selected by click. I wonder how to make the inserted record to also have a "option button". struct ListEditModeSubviewUpdateTest: View { @State private var data = [Int]() @State private var editMode = EditMode.inactive @State private var selects = Set<Int>() @State private var base = 0 var body: some View{ VStack{ Button { if editMode.isEditing{ editMode = .inactive }else{ editMode = .active } } label: { Text(editMode.isEditing ? "Done" : "Edit") } Button { base += 1 data.append(base) } label: { Text("Insert") } List(selection: $selects){ ForEach(data, id:\.self){item in Text(String(item)) } .onDelete{ data.remove(atOffsets: $0) } } } .environment(\.editMode, $editMode) } }
Replies
0
Boosts
0
Views
593
Activity
Jun ’22
How to prevent the background color from going beyond the safe area when rotating the simulator
I need to use some "uikit view controller" in my swiftui app. I have encapsulate the vc in a representable view. It works well. However, the background color will extend outside of safe area when I rotate the simulator from portrait to landscape and back to portrait. I want the background color always to stay inside safe area. I prototype a sample code to illustrate the issue. struct ContentView: View { var body: some View { ZStack{ Color.gray CustomRepresentation() } } } struct CustomRepresentation: UIViewControllerRepresentable{ func makeUIViewController(context: Context) -> some UIViewController { return UIViewController() } func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { } } If I comment the CustomRepresentation(), the gray color will stay inside the safe area all the time during rotating. So I realize the key point is CustomRepresentation(). But I don't know how to fix it.
Replies
0
Boosts
0
Views
984
Activity
Oct ’22
Reload images from PHPickerViewController
I'm writing an app which allow users to pick images from photo library by swiftUI. I wrap PHPickerViewController in representable to achieve the functionality. The benefit is that users don’t need to explicitly authorize my app to select photos. func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) Currently, I get images by picker(::) method above and save images in my app in order to reload images the next time users launch the app without needs to request authorization. Obviously, if the app stores references to the selected images, rather than images themselves, it can prevent from taking up large amounts of space. Is it meaning that I have to prompt to users for requesting authorization to access the library? Is there any approach only to use references and reload images which were selected by users previously from photo library using PHPickerViewController, supporting no need to request authorization.
Replies
1
Boosts
0
Views
1.6k
Activity
Nov ’22