Post

Replies

Boosts

Views

Activity

Reply to How to drag drop to reorder items in a horizontal scroll view?
The complex thing is to allow both scroll and move. I do it by using longPress for move and normal press for scrolling. Here is a code snippet: struct ContentView: View { struct Item: Identifiable { let id = UUID() var pos: Int var value: String var color: Color var onMove: Bool = false } @State var items : [Item] = [ Item(pos: 0, value: "A", color: .blue), Item(pos: 1, value: "B", color: .red), Item(pos: 2, value: "C", color: .blue), Item(pos: 3, value: "D", color: .red), Item(pos: 4, value: "E", color: .blue), Item(pos: 5, value: "F", color: .red), Item(pos: 6, value: "G", color: .blue), Item(pos: 7, value: "H", color: .red), Item(pos: 8, value: "I", color: .blue), Item(pos: 9, value: "J", color: .red), Item(pos: 10, value: "K", color: .blue)] @GestureState private var isDetectingLongPress = false @State private var completedLongPress = false @State private var activeLongPress = false var longPress: some Gesture { LongPressGesture(minimumDuration: 0.5) // LongPress to move, shortpress to scroll .updating($isDetectingLongPress) { currentState, gestureState, transaction in gestureState = currentState activeLongPress = true } .onEnded { finished in self.activeLongPress = !finished } } var body: some View { ScrollView(.horizontal) { HStack(spacing: 5) { ForEach(items) { item in Rectangle() .fill(item.onMove ? .green : item.color) .frame(width:40, height:40) .overlay { Text("\(item.value)") } .gesture( DragGesture(minimumDistance: 2) .onChanged { _ in items[item.pos].onMove = true } .onEnded { value in let shift = Int(value.translation.width / 45) // 40 width + 5 interspace let newPos = item.pos+shift if newPos >= 0 && newPos <= 7 { let element = items.remove(at: item.pos) items.insert(element, at: newPos) items[newPos].onMove = false for itemPos in 0...7 { items[itemPos].pos = itemPos } } } ) .gesture(longPress) } } } .scrollDisabled(activeLongPress) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’25
Reply to Design Minimum Functionality
It seems that equivalent information is available on most restaurants websites. So what would be the added value of your app ? I guess that's what the rejection is based on. That's what guideline 4.2 states: 4.2 Minimum Functionality Your app should include features, content, and UI that elevate it beyond a repackaged website. If your app is not particularly useful, unique, or “app-like,” it doesn’t belong on the App Store. If your App doesn’t provide some sort of lasting entertainment value or adequate utility, it may not be accepted. Some idea: help find a restaurant close to my location where waiting time is low at some time help find where affluence limited at this time find restaurant opened at a given time (late or hourly hours)
Jan ’25
Reply to How do you make buttons inline with each other?
Welcome to the forum. Did you try to insert in a HStack ? struct NormalPageView: View { var body: some View { VStack { NavigationView { Form { Section { HStack { Image(systemName: "house.fill") Spacer() Image(systemName: "plus") Spacer() Image(systemName: "gearshape.fill") } } } } } } } If that answers your question, don't forget to close the thread by marking this answer as correct. Please note: when you post code, use code formatter tool to make it readable.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’25
Reply to Rectangle change size by swipe
Declare state var for rectangle width and height. Use this var in the .frame() Change the values when you swipe. Here is a code example: struct BlueRectangleView: View { @State var height: CGFloat = 100 @State var width: CGFloat = 200 // If you also want to change width var body: some View { VStack { Rectangle() .fill(Color.blue) .frame(width: width, height: height) .cornerRadius(10) .shadow(radius: 5) .padding() .gesture( DragGesture(minimumDistance: 5) .onChanged { value in let newHeight = height + value.translation.height / 20 // /20: To slow down change let newWidth = width + value.translation.width / 20 // /20: To slow down change if newHeight > 5 && newHeight < 500 { height = newHeight print("New height\(height)") } if newWidth > 5 && newWidth < 400 { width = newWidth print("New width\(width)") } } ) } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.white) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’25