swift 点击响应视图之外的地方
生活随笔
收集整理的這篇文章主要介紹了
swift 点击响应视图之外的地方
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
?
需求:點擊紅框 才 隱藏view,
現(xiàn)象,在touch Began 里面寫的時候, 紅色和藍色框都會消失
/// 點擊containerView 之外的地方隱藏override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {super.touchesBegan(touches, with: event)if let touch = touches.first{let location = touch.location(in: self)let convertPoint = self.convert(location, to: containerView)if !containerView.bounds.contains(convertPoint){hiddendShareView()}}}/// 點擊隱藏當前界面private func hiddendShareView() {UIView.animate(withDuration: 0.25, animations: {self.alpha = 0self.layoutIfNeeded()}) { (res) inself.removeFromSuperview()}}
轉(zhuǎn)載于:https://www.cnblogs.com/qingzZ/p/11075981.html
總結(jié)
以上是生活随笔為你收集整理的swift 点击响应视图之外的地方的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL性能优化整合持续更新
- 下一篇: 借助树的概率dp(期望)+数学-好题-h