
需求:点击红框 才 隐藏view,
现象,在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 = 0
self.layoutIfNeeded()
}) { (res) in
self.removeFromSuperview()
}
}