简体   繁体   English

在UIView上进行手势

[英]Gesture on a UIView

I'm drawing on a UIView called paintingView and I can drag some imageview on it from a scrollview; 我在一个名为paintingViewUIView上进行paintingView ,可以从滚动视图中拖动一些图像视图。 but I don't drag these objects directly on paintingView but in a UIView over it called "over". 但我不会将这些对象直接拖动到paintingView上,而是将其拖到UIView上的“ over”上。 This "over" has userinteractionenabled = NO , so in this way I can draw without problems. 此“结束”具有userinteractionenabled = NO ,因此通过这种方式,我可以毫无问题地进行绘制。

Here is my problem: To leave these object from "over" I should add some gesture (a double tap or a longpress); 这是我的问题:要使这些对象脱离“上方”状态,我应该添加一些手势(双击或长按); but this "over" has userinteractionenabled = NO so gestures don't work Do you have any idea how to add gesture to these objects? 但是此“结束”具有userinteractionenabled = NO因此手势不起作用您是否知道如何向这些对象添加手势?

Make a subclass of UIView for your "over" view and overwrite hitTest:withEvent: . 为您的“上方”视图创建UIView的子类,并覆盖hitTest:withEvent:

If you have a touch on a dragged-in view, handle it (return the dragged-in view), otherwise return [super hitTest:withEvent:]; 如果您对拖入的视图有触摸,请进行处理(返回拖入的视图),否则返回[super hitTest:withEvent:]; .

(And turn userInteractionEnabled on again). (然后再次打开userInteractionEnabled )。

Or another idea: 或另一个想法:

Put an UITapGestureRecognizer with minimumTouches: of two onto your paintingView and check, if the touch is within a dragged-in view. 把一个UITapGestureRecognizer与minimumTouches:两到您的paintingView和检查,如果触摸是一种拖累,在视图中。 If so handle it here. 如果是这样,请在这里处理。 But you probably draw accidentially with that approach. 但是您可能会意外地使用这种方法。

You could also recognize the double-tap on your own. 您也可以自行识别两次。 You probably already did overwrite touchesBegan: etc. You could recognize it there, go through the subviews of your "over" view and check, if it was in the bounds of an image. 您可能已经覆盖了touchesBegan:等。您可以在那里识别它,浏览“上方”视图的子视图并检查它是否在图像的边界内。 If so handle it and don't draw for that touch. 如果这样的话,请不要触摸它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM