【问题标题】:Gesture Recognizer on sub-view outside view's bounds视图边界外的子视图上的手势识别器
【发布时间】:2014-03-31 20:05:17
【问题描述】:

我不确定这是否可行,但我有一个可以通过平移手势在屏幕上拖动的视图。选择视图后,视图的角上会出现小抓手,允许用户调整视图大小。问题是,那些夹具超出了视图的界限(它们仍然出现,因为Clipsubviews已关闭),但在选择绘制的部分时,这些夹具上的手势识别器在视图之外绘制的部分时不会触发。使视图更大以实际握住抓手会破坏许多基于视图大小的已创建逻辑,所以这对我来说是最后的手段。

有没有其他方法可以让手势识别器处理在其父视图之外绘制的视图?

【问题讨论】:

  • 你是怎么得到的?

标签: ios iphone objective-c uigesturerecognizer


【解决方案1】:

您可以尝试在 UIView 子类中覆盖 hitTest:withEvent:,并返回抓取器视图。

【讨论】:

  • 根据文档Points that lie outside the receiver’s bounds are never reported as hits, even if they actually lie within one of the receiver’s subviews. This can occur if the current view’s clipsToBounds property is set to NO and the affected subview extends beyond the view’s bounds. 所以我认为这行不通。
  • @KevinDiTraglia 我相信这是默认实现。您必须继承、覆盖和更改其行为。
  • 好的,我试试看。
  • 我用 point(inside:with:) 代替,它更容易而且也有效!感谢您指出正确的方向!
猜你喜欢
  • 2013-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
  • 1970-01-01
  • 2013-03-14
  • 1970-01-01
相关资源
最近更新 更多