I\'m working with sprite kit and if the user touches the screen, the actions within
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
You can use boolean class variable to stop interaction while method is performing, and after that you can just change value of boolean, at the end of the method.
Use UIApplication.shared.beginIgnoringInteractionEvents()
at the end of the first method, then change value of boolean and then use another method with start line UIApplication.shared.endIgnoringInteractionEvents()
.
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!")
}
SomeView()
.allowsHitTesting(false)
In Swift 3.0 is:
self.view.isUserInteractionEnabled = false
If you want to disable a Buttons user's interaction, just do this when the screen loads.
self.btnname.isUserInteractionEnabled = false
If you want to disable the user interaction as a view, it will be same just remove the button name and add the view's name.
If for some reasons, you want to enable interaction, just change "false" to "true".
just go to storyboard and uncheck this option in any object which u want to disable the interaction of the user