Swift: how to disable user interaction while touch action is being carried out?

后端 未结 8 2427
执念已碎
执念已碎 2021-02-12 03:27

I\'m working with sprite kit and if the user touches the screen, the actions within

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
            


        
8条回答
  •  深忆病人
    2021-02-12 04:14

    For SwiftUI, expanding on @mojtaba-hosseini answer. You wanna make sure you fill your view with some color, except Clear color (you can always change opacity). I've also added blur to hide elements. Here's what worked for me:

    SwiftUI:

    ZStack{
        SomeView().blur(radius: 12)
        Rectangle()
            .fill(Color.white.opacity(0))
            .allowsHitTesting(false)
    }
    

    Another way to disable user interactions like scroll or button taps, but attach an action to user taps (for example a message to users that this feature is coming or behind a paywall):

    SwiftUI:

    VStack{
        SomeView().blur(radius: 12)
    }
    .contentShape(Rectangle())
    .onTapGesture {
        print("No access!")
    }
    

提交回复
热议问题