ios - 等到用户触摸屏幕。迅速
问题描述
发生某些事情后,我会用标签显示视图,
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()
})
我怎样才能等到我触摸屏幕?
解决方案
只需将 tapGesture 添加到您的视图
在viewDidload
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
self.view.addGestureRecognizer(tapGesture)
handleTapGesture
@IBAction func handleTapGesture(_ recognizer: UITapGestureRecognizer) {
UIView.animate(withDuration: 0.5, animations: {
muView.alpha = 0
}, completion: { (bool) in
myView.removeFromSuperview()
})
}
推荐阅读
- oracle - 我想用其他表数据中的数据更新表 emp_appointment
- javascript - 我需要帮助制作响应式菜单
- java - Java如何发送特殊字符是post
- sql - 具有多重表的条件
- css - 我希望特定高度的 div 可以根据需要增加宽度以容纳文本
- snowflake-cloud-data-platform - 雪花更改列以具有默认值
- maven - “mvn verify”与“mvn test”有什么区别?
- reactjs - 使用 shopify 验证外部 create-react-app 自定义应用程序
- javascript - 在 Angular 中使用真实路径:找不到模块
- javascript - 在不打开窗口的情况下加载页面