在这个拖放游戏 ( adapted from this tutorial ) 中,玩家必须将标签与正确的目标相匹配。我将其设置为如果触摸结束并且标签的中心位于目标内部,则它将从屏幕上删除并重新开始游戏。
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if label.name == "letters" {
if lettersBin.frame.contains(label.position) {
// remove it and create a new label
label.removeFromParent()
setupDragLabel()
但是,如果玩家将错误的标签放入垃圾箱,我想触发通知,因此:
else if label.name == "numbers" {
if lettersBin.contains(label.position) ...
我要写什么来完成这个?我是否要在屏幕上显示另一个标签?
最佳答案
使用 UIAlertController 可能是最简单的。您可以添加消息和按钮操作以显示用户错误。
let converterAction = UIAlertController(title: "Your title here", message: "Your message to the user here", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default){ _ in
//Any custom action to happen here
}
converterAction.addAction(okAction)
present(converterAction, animated: true, completion: nil)
关于swift - 如果标签被放置在错误的目标上,如何触发通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51865111/