Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - Apple Watch Menu (Force Touch)

I'm trying to implement a menu on Apple Watch using SwiftUI but I can't find a way to do it. Even on the interface.storyboard, I can't drag/drop the menu.

Did you manage to make it work with SwiftUI? If yes, how?

I searched online but nothing so far.

like image 317
Daymo502 Avatar asked Aug 26 '19 23:08

Daymo502


People also ask

Did they remove Force Touch on Apple Watch?

Unfortunately, Apple has removed this touch technology with the introduction of watchOS 7. Here we will know all about the Force Touch on Apple Watch and why the company has killed this incredibly helpful touch technology. If you are curious to know more about it, read on to unravel the truth.

Does Apple Watch have Force Touch?

Easily access more options with just a touchThe Apple Watch's Force Touch feature is the wearable device's version of 3D Touch on the iPhone. These features let you unlock new options and shortcuts by pressing on your device's screen.


1 Answers

Yes, this is possible. It's important to remember that unlike on iOS, a view can have only one single context menu, individual elements within the view can not have their own context menu.

Anyway, to implement a context menu (force touch menu) on Apple Watch with SwiftUI, add the .contextMenu() modifier to top-most view in your body

Example:

var body: some View {
    Group {
        Text("Hello Daymo")
    }
    .contextMenu(menuItems: {
        Button(action: {
            print("Refresh")
        }, label: {
            VStack{
                Image(systemName: "arrow.clockwise")
                    .font(.title)
                Text("Refresh view")
            }
        })
    })
}

Edit the button (or add buttons) as you see fit.

like image 64
Will Avatar answered Oct 09 '22 17:10

Will