skip to Main Content

I would like to implement this "swipe up view" from the apple "find my" app in my app with swiftui. Does anyone know how this works or what I can look for? Best regards

enter image description here

enter image description here

enter image description here

2

Answers


  1. Starting with iOS 16, you can achieve these with the presentationDetents(_:) modifier.

    See this article for examples.

    Login or Signup to reply.
  2. Yeah, presenting a sheet isn’t quite the same, and there’s no built-in SwiftUI view that will do this.

    Here are a few pointers in the right direction:

    1

    Try a ZStack as the basic structure:

    ZStack(alignment: .bottom) {
        mapView
        sheetView
    }
    

    The sheet floats over the map and is aligned to the bottom (you can use .frame(height:) to set its height as needed). The mapView should be full height since the sheet background is translucent

    2

    A sheet background could look something like this:

        // Sheet background:
        RoundedRectangle(cornerRadius: 18, style: .continuous)
            .fill(.regularMaterial)
            .edgesIgnoringSafeArea(.bottom)
        .overlay {
        // Handle
        Capsule()
            .fill(.ultraThinMaterial)
            .colorScheme(.dark)
            .frame(width: 60, height: 8)
            .padding()
    }
    

    3

    And you could use a drag gesture to start working on implement detents:

        @State var sheetHeight = 300.0
    
    // in body:
        sheetView
            .frame(height: sheetHeight)
            .gesture(DragGesture(minimumDistance: 1)
                .onChanged{ v in
                    sheetHeight = 300 - v.translation.height
                }
                .onEnded{ _ in
                    sheetHeight = 300
                }
            )
    

    From there, Maps has a ton of behavior: custom detents, content transitioning to scrollable at the top detent, icons showing and hiding, switch detent when the map is panned, etc.

    There’s no magic built in way to do that stuff — it’s just custom UI work. No reason you can’t implement it in SwiftUI (or in UIKit if you prefer). Have fun!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search