swift - UIView 更改其大小后 UIGestureRecognizer 延迟
问题描述
我里面有一个视图和一个子视图。在子视图中,有一些手势识别器可以工作。都是在创建子视图时正常添加的,例如:
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 都有一个 touches 方法。所以你可以删除点击手势并尝试输入这个函数
覆盖 func touchesBegan()
我省略了参数,当你开始输入 touches 时......它会自动完成。将要执行的代码放入其中。同样,您也可以使用触摸开始、触摸结束的方法。试试 UIVIEW Touch 方法。希望他们不会滞后,您的问题将得到解决。
推荐阅读
- windows - SQL Server Management Studio 安装程序 exe 无法启动
- r - 在 R 中使用 terra 包从不同程度的栅格镶嵌错误?
- git - 如何获取特定版本的 Chromium 源代码?
- swift - 如何在swift中进行函数回调
- node.js - 如何解决 Google App Engine 上 VueJs / Express / Mongo 应用程序的 API 响应的“启用 Javascript”错误
- python - 我可以从 Django views.py 中的另一个函数调用一个函数吗?
- python - 为什么要将 RNN/LSTM 的训练和测试数据用于股票预测?
- laravel - 表会话 laravel 中的 user_id 用于多守卫
- swift - 将旋转的 NSImageView 作为子视图的 NSView 保存到 pdf 文件的问题 - NSImageView 未旋转
- python - (堆叠)带有单独标记观察的直方图