ios - 无法在其父视图之外平移手势较小的 UIView
问题描述
我有一个UIView
包含许多UIView
子视图的。当用户尝试平移其中一个子视图时,我希望他们能够将其拖动到屏幕上的任何其他位置。
但是,我只能在UIView
它们包含的较大视图中拖动这些较小的视图。当用户第一次尝试平移较小的视图时,有没有办法以编程方式在顶部创建第二个 UIView,然后在第二个 UIView 周围拖动?第二个 UIView 将与第一次接触的较小视图相比是全新的。
这是我目前拥有的处理函数,仅供参考。不过,我不知道我会在哪里以编程方式创建第二个 UIView。任何帮助将不胜感激:
@objc func handlePanGesture(sender: UIPanGestureRecognizer) {
// get translation
var translation = sender.translation(in: view)
sender.setTranslation(CGPoint.zero, in: view)
// drag around current UIView
var newView = sender.view as! UIView
newView.center = CGPoint(x: newView.center.x+translation.x, y: newView.center.y+translation.y)
newView.isMultipleTouchEnabled = true
newView.isUserInteractionEnabled = true
if sender.state == UIGestureRecognizer.State.began {
// add something you want to happen when the Label Panning has started
}
if sender.state == UIGestureRecognizer.State.ended {
// add something you want to happen when the Label Panning has ended
}
if sender.state == UIGestureRecognizer.State.changed {
// add something you want to happen when the Label Panning has been change ( during the moving/panning )
} else {
// or something when it's not moving
}
}
解决方案
有什么方法可以在任何地方拖动较小的视图,同时保持我现在的布局
由于触摸的工作方式,默认情况下,当视图到达其父视图的边界时,它是不可能被触摸的。但是您可以通过在超级视图中覆盖来克服该限制hitTest
。
推荐阅读
- java - 重新安装 Windows 后 Flutter 构建失败
- apache-spark - PySpark ETL 更新数据框
- python-sphinx - 如何在 python-sphinx 中创建等式末尾的数字?
- php - Laravel:获取数据透视表关联
- ruby-on-rails - Rails 5:删除按钮 link_to 没有按预期工作
- android - 带有标题的 Android 概述布局
- r - 如何在有条件的情况下获得 R 中多列的中位数(根据另一列)
- python - pyqt:从 qlineEdit 中删除布局
- powershell - 找不到依赖包(System.Runtime)
- apache-spark - 不允许操作:Spark sql 上的 hive 存储