Friday, August 11, 2023
HomeiOS Developmentios - SwiftUI Contentview click on are taking a number of makes...

ios – SwiftUI Contentview click on are taking a number of makes an attempt to occur


Iam engaged on MacOS Software, My total code is written in Swift however for including MenuItem I most well-liked to make use of SwiftUI ContentView. To try this I’ve written following code.

class StatusBarController {
    
    var statusBar: NSStatusBar!
    var statusItem: NSStatusItem!
    var nsMenu = NSMenu()
    
    init(delegate: AppDelegate) {
        
        statusBar = NSStatusBar()
        statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)

        statusItem.button?.picture = NSImage(systemSymbolName: "star.fill", accessibilityDescription: "Standing bar icon")

        let menuItem = NSMenuItem()
        let controller = NSHostingController(rootView: ContentView())
        
        controller.view.body.dimension = CGSize(width: 250, peak: 320)
        menuItem.view = controller.view
        
        
        nsMenu.addItem(menuItem)
        statusItem.menu = nsMenu
    }
}

That is working effective Im in a position to current ContentView efficiently however in ContentView there’s click on motion added on label. But it surely’s taking a number of makes an attempt(3-4) to simply do single click on. I did lot of analysis it appears challenge of home windows hierarchy. Could also be Contentview window shouldn’t be in entrance and therefore click on shouldn’t be passing by correctly.What ought to I do right here in order that click on will occur instantly in single click on.

That is my content material view:


struct ContentView: View {

    var physique: some View {

        VStack(alignment: .main, spacing: 0) {
           
         
            HStack() {
                Textual content("Stop")
                        .font(.title3)
                        .fontWeight(.medium)
                        .foregroundColor(.black)
                        .padding(.main, 10)
                        .padding(.prime, 10)
                Spacer()
            }
            .contentShape(Rectangle()).onTapGesture {
              
                //That is the motion Im speaking about
                NSApp.terminate(self)
            }
        }
    }
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments