[英]Sending touch gestures to UIImageView subview of UIScrollView
我编写了一个UIImageView,可以在其中绘制内容。 因此,它跟踪并记录用户的触摸。 在窗口中使用时,效果很好。
但是,然后我将其添加为驻留在视图控制器中的UIScrollView的子视图。 当我现在尝试使用它时,UIImageView内部的触摸手势只是滚动整个视图,而不是在UIImageView内部绘制。
如何将同样位于UIImageView内部的对UIScrollView所做的手势引用到UIImageView。
我希望这是有道理的
最好的祝福
编辑:我已经将所有以下属性: canCancelContentTouches
, exclusiveTouch
和delaysContentTouches
为NO。
现在,当我触摸UIImageView时,它不会滚动,但仍不会调用以下方法: touchesBegan:withEvent:
, touchesMoved:withEvent:
或touchesEnded:withEvent:
分别位于ViewController中
设置exclusiveTouch
的的UIImageView的财产YES
(这意味着,当的UIImageView被触摸时,那一抹不会对任何其他视图效果)
您希望应用程序如何决定是触摸滚动视图还是在图像视图中绘制?
假设您要一根手指来画,而两根手指要滚动。 如果您的目标是iOS 5.0,则很简单:
self.scrollView.panGestureRecognizer.minimumNumberOfTouches = 2;
如果您要定位的是较早的iOS,则不能使用panGestureRecognizer
属性。 您必须在滚动视图的gestureRecognizers
属性中进行挖掘以找到正确的识别器。 在此处查看我的答案以获取示例代码。
UIScrollView不会为此触发触摸事件方法,因此必须子类化UIScrollView。 像下面。
@interface AppScrollView : UIScrollView {
}
- (id)initWithFrame:(CGRect)frame;
@结束
#import "AppScrollView.h"
@implementation AppScrollView
- (id)initWithFrame:(CGRect)frame
{
if ([super initWithFrame:frame]){
}
return self;
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
// If not dragging, send event to next responder
if (!self.dragging)
[self.nextResponder touchesEnded: touches withEvent:event];
else
[super touchesEnded: touches withEvent: event];
}
@end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.