我创建了一个UIViewController,它包含一个UIView对象.
我希望UIView对象响应1手指单击,并且还用2个手指捏住.
我点击了xib中的“User Interaction Enabled”和“Multiple touch”选项.
我在UIView函数initWithFrame:中创建了UITapGestureRecognizer和UIPinchGestureRecognizer,因为它是UIView对象的唯一入口点.但该对象不响应UIGestureRecognizer对象.为什么?或者,放置UIGestureRecognizer对象的最佳位置在哪里?
- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code // single tap UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; singleTap.numberOfTapsrequired = 1; singleTap.numberOftouchesrequired = 1; [self addGestureRecognizer: singleTap]; // 2 fingers pinch UIPinchGestureRecognizer* doubleMove = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleMove:)]; [self addGestureRecognizer: doubleMove]; } return self; }