UIGestureRecognizer在UIView更改其大小后延迟



我有一个视图和一个子视图。在子视图中,有一些手势识别器可以工作。它们都是在创建子视图时正常添加的,例如:

let assetViewTapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleAssetViewTap(_:)))
assetViewTapGesture.delegate = self
assetView.addGestureRecognizer(assetViewTapGesture)

在超级视图中,我有一个UIPinchGestureRecognizer,它调用子视图中的一个函数,该函数反过来改变子视图中帧的大小:

public func scale(newWidth:CGFloat){
let factor:CGFloat = newWidth / self.internalAssetView.frame.width
self.internalAssetView.frame = CGRect(x: self.internalAssetView.frame.origin.x, y: self.internalAssetView.frame.origin.y, width: newWidth, height: self.internalAssetView.frame.height)
self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: newWidth + additionParameter, height: self.frame.height)
}

当我捏的时候,一切都表现得很好,视图的大小也会按照应该的方式改变。

问题:在挤压结束后,我点击以在子视图中启动TapGestureRecognizer。它正在发射,但仅仅几秒钟后。事实上,在点击屏幕和实际启动识别器之间,我捏的视图越多,等待的时间就越长。为什么改变视图的帧会影响手势识别器发射的延迟?

我不知道原因,但我可以提供一个可能缓解您问题的解决方案。

不需要添加独立的点击手势,事实上,每个UIVIEW都有一个触摸方法。因此,您可以删除点击手势,并尝试键入此功能

覆盖函数触摸Began((

我省略了这些论点,当你开始输入触摸时。。。它将自动完成。把你想执行的代码放在里面。同样,你也可以使用touch-start和touch-stend方法。尝试UIVIEW Touch方法。希望他们不会落后,你的问题会得到解决。

最新更新