简体   繁体   中英

SwiftUI SF Symbols Button in NavigationBar not working

I'm trying to use a button that is a SF Symbol Image as the trailing navigation bar item, however, when clicking the button on a REAL IPHONE, it's very very unreliable and I end up clicking it 30+ to only get 1 click registered.

My code looks like this:

NavigationView {
            List {
                Text("Example")
            } .navigationBarTitle("Tasks").navigationBarItems(trailing:

            Button(action: { print("I was clicked!")}) {
                Image(systemName: "plus")
            }

            )
}

However, when I put the same button outside of navigationBarItems , the button registers clicks much easier.

What can I do here?

Is this a problem with SwiftUI, if so, is there a workaround?

Thanks!

You can add padding to the image to increase the hitbox of the image

Image(systemName: "plus")
    .padding([.leading, .top, .bottom])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM