不知道我做错了什么,但这里有一个简化的例子:
@interface Test : NSObject<UIGestureRecognizerDelegate> {
UIView *_someParentView;
UIView *_someChildView;
}
- (id)initWithParentView:(UIView *)parentView;
@end
@implementation Test
- (id)initWithParentView:(UIView *)parentView
{
if (self = [super init])
{
_someParentView = parentView;
}
return self;
}
- (void)addSubViewsWhenReady
{
_someChildView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
_someChildView.backgroundColor = [UIColor blackColor];
[_someChildView setUserInteractionEnabled:YES];
[_someParentView addSubview:_someChildView];
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
singleFingerTap.delegate = self;
[_someChildView addGestureRecognizer:singleFingerTap];
}
- (void)handleSingleTap:(id)sender
{
NSLog(@"handle the single tap");
}
@end
输出:“处理单击”永远不会被记录。关于我做错了什么的任何想法?
谢谢!