objective-c 如何禁用触摸检测?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1101965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I disable the touch detection?
提问by lostInTransit
How can I disable the touch detection within the action that running, because I don't want the character flying in the sky like a superman if the player clicking and clicking within the action, the character will never land if they keep clicking. I found the method "isDone", is that relate to this method?? player click -> action(cannot click within the action) -> action finish -> click again..... that's what i want~
如何在运行的动作中禁用触摸检测,因为如果玩家在动作中点击和点击,我不希望角色像超人一样在天空中飞行,如果他们继续点击,角色将永远不会着陆。我找到了方法“isDone”,这与这个方法有关吗??玩家点击->动作(不能在动作内点击)->动作完成->再次点击.....这就是我想要的~
回答by Biranchi
This is the best answer to your question:
这是您问题的最佳答案:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
回答by lostInTransit
Disable user interactions in your view till the action completes and then enable it again.
在您的视图中禁用用户交互,直到操作完成,然后再次启用它。
To disable touch
禁用触摸
[self.view setUserInteractionEnabled:NO];
To enable touch
启用触摸
[self.view setUserInteractionEnabled:YES];
Please try and be a bit more concise of what you want the next time.
请尝试在下次更简洁地说明您想要的内容。
回答by Maninderjit Singh
In Swift 2.2
在 Swift 2.2 中
self.view.userInteractionEnabled = false
回答by Aleksey Timoshchenko
Swift 3.0
斯威夫特 3.0
self.view.isUserInteractionEnabled = false
回答by Matt Rix
Just gonna make a wild assumption that you're talking about the specific Action class in Cocos2D. If that's true, then you should know that every Action has an "isDone" Bool you can check to see if it's done. Let me know if that's what you're asking and I'll post an example, but there's a huge chance you could be talking about something else because your wording is so confusing ;)
只是假设您正在谈论 Cocos2D 中的特定 Action 类。如果这是真的,那么您应该知道每个操作都有一个“isDone”布尔值,您可以检查它是否已完成。如果这就是您要问的问题,请告诉我,我会发布一个示例,但是您很有可能在谈论其他事情,因为您的措辞太令人困惑了 ;)
回答by Dave Martorana
You could always put a transparent UIView over top of the area you want to "disable" tap input for, have it listen for taps, and have it ignore them. Remove the UIView (or hide it) when you want input to be listened to again.
你总是可以在你想要“禁用”点击输入的区域顶部放置一个透明的 UIView,让它监听点击,并让它忽略它们。当您希望再次收听输入时,请移除 UIView(或隐藏它)。
回答by Xn0vv3r
Why don't you use some kind of (simple version) boolean to remember i.e. isInAction = true and after the action finished isInAction = false...
为什么不使用某种(简单版本)布尔值来记住即 isInAction = true 并且在操作完成后 isInAction = false ...
So when someone clicks, u use something like
所以当有人点击时,你使用类似的东西
if (!isInAction) {
isInAction=true;
try {
doYourAction;
} catch {
...
} finally {
isInAction=false;
}
}
// The Code is some kind of pseudocode, because I haven't yet programmed for the IPhone, just to visualize what I mean.
// 代码是某种伪代码,因为我还没有为 iPhone 编程,只是为了形象化我的意思。
回答by Mattias Akerman
Perhaps I didn't understand your question but is this what you're looking for?
也许我不明白你的问题,但这就是你要找的吗?
- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[Superman Fly];
self.isTouchEnabled = NO;
}
- (void)SupermanLanded{
self.isTouchEnabled = YES;
}

