从笔尖加载的视图不会收到触摸事件

我正在尝试从笔尖加载视图并将其添加到主视图。 这是我的代码。

我在@interface AddTaskView:UIViewinitWithFrame中加载了nib:

  - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { NSLog(@"init with frame"); // Initialization code NSArray *addTaskArrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"AddTaskView" owner:self options:nil]; self=[addTaskArrayOfViews objectAtIndex:0]; } return self; } 

之后,我初始化视图并将其添加到主视图中:

  self.addTaskView=[[AddTaskView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)]; [self.view addSubview:self.addTaskView]; 

一切工作正常,但AddTaskView不会收到触摸事件。 我有三个button,当我尝试推动他们时,他们不会收到这些动作。 我做了“AddTaskView”types的笔尖,但没有任何运气。 我也看了子视图,“AddTaskView”是顶视图。

我在AddTaskView中添加了这段代码,看看我是否能够触摸并且没有回应:

  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touch"); } 

我如何获得回应触摸事件的机会?

我认为你必须注册一个触摸调度器,然后尝试接触….以下是代码

 -(void)registerWithTouchDispatcher{ [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0swallowsTouches:YES];} -(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{ return YES;} -(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{ touchLocation = [touch locationInView:[touch view]]; NSLog(@"Touch is working");} 
 [UIView beginAnimations:@"MoveAndStrech" context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationBeginsFromCurrentState:YES]; [UIView commitAnimations];