Ios 等待用户触摸屏幕。敏捷的
发生某些事情后,我会让视图显示一个标签Ios 等待用户触摸屏幕。敏捷的,ios,swift,wait,Ios,Swift,Wait,发生某些事情后,我会让视图显示一个标签 let myView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100)) let label = UILabel(frame: CGRect(x:0,y:0,width: 100, height: 100)) myView.addSubview(lebel) self.view.addSubview(myView) myView.alpha = 0 UIView.animate(
let myView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
let label = UILabel(frame: CGRect(x:0,y:0,width: 100, height: 100))
myView.addSubview(lebel)
self.view.addSubview(myView)
myView.alpha = 0
UIView.animate(withDuration: 0.5, animations: {
myView.alpha = 1
})
现在我想让你等到屏幕上出现点击,然后
UIView.animate(withDuration: 0.5, animations: {
muView.alpha = 0
}, completion: { (bool) in
myView.removeFromSuperview()
})
我怎样才能等到触摸到屏幕?只需将点击手势添加到视图中即可 在viewDidload 手势
@IBAction func handleTapGesture(_ recognizer: UITapGestureRecognizer) {
UIView.animate(withDuration: 0.5, animations: {
muView.alpha = 0
}, completion: { (bool) in
myView.removeFromSuperview()
})
}
除了Abdelahad的答案之外,您还应该将let myView声明为一个属性,以便在@IBAction func HandletApsignizer\uRecognitizer:UITapGestureRecognitizer{}中使用它。因此,新代码如下所示:
@IBAction func handleTapGesture(_ recognizer: UITapGestureRecognizer) {
UIView.animate(withDuration: 0.5, animations: {
self.myView.alpha = 0
}, completion: { (bool) in
self.myView.removeFromSuperview()
})
}
最后,我在代码中发现了您的小错误。muView是错误的,myView是正确的。等等什么?您是否需要在等待中明确执行任何操作?否则,点击手势识别器可能会触发…查看如何使用UITapGestureRecognitor。它使您能够监听视图的顶部,并允许您在点击时选择要触发的函数。
@IBAction func handleTapGesture(_ recognizer: UITapGestureRecognizer) {
UIView.animate(withDuration: 0.5, animations: {
self.myView.alpha = 0
}, completion: { (bool) in
self.myView.removeFromSuperview()
})
}