【发布时间】:2015-12-03 10:21:45
【问题描述】:
【问题讨论】:
标签: ios xcode swift custom-view
【问题讨论】:
标签: ios xcode swift custom-view
你可以像这样使用touchesBegan 来跟踪它:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch= [touches anyObject];
if ([touch view] == self.view)
{
// do stuff
}
}
对于快速:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
if touch.view == self.view {
// do stuff
}
}
super.touchesBegan(touches, withEvent:event)
}
【讨论】:
您可以在覆盖整个屏幕的自定义视图下添加UIView,将其设置为 0.1 左右的 alpha。然后,您可以向其添加 tapGestureRecognizer 以捕获自定义视图之外的所有触摸。
请记住在隐藏自定义视图时也隐藏叠加层,以免之后的触摸被阻止。
【讨论】: