2012-05-16 62 views
0

我想從筆尖加載視圖並將其添加到主視圖。這是我的代碼。從筆尖加載的視圖不會收到觸摸事件

我裝筆尖在@interface AddTaskView:UIViewinitWithFrame

- (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沒有按不會收到觸摸事件。我有三個按鈕,當我嘗試推動它們時,他們不會收到這些動作。 我做了「AddTaskView」類型的筆尖,但沒有任何運氣。我也看了子視圖,「AddTaskView」是頂視圖。

我在AddTaskView加入這個代碼,看看,如果我得到的觸摸和無反應:

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

我如何得到一個機會來響應觸摸事件?

回答

0
[UIView beginAnimations:@"MoveAndStrech" context:nil]; 

[UIView setAnimationDuration:1]; 

[UIView setAnimationBeginsFromCurrentState:YES]; 

[UIView commitAnimations]; 
+0

?這是如何回答這個問題的? – Krishnabhadra

0

我認爲你必須註冊一個觸摸調度程序,然後試圖讓觸摸....下面是你回答任何其他問題的代碼爲

-(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");} 
相關問題