2012-05-03 198 views
0

我正面臨與UITouch有關的問題。我不知道如果不是這樣的話。觸摸不檢測?

下面是代碼:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    if([touch view] == self.transView) 
    { 
     NSLog(@"Began"); 
     CGPoint startLocation = [touch locationInView:transView]; 
     startX = startLocation.x; 
     startY = startLocation.y; 
    } 
} 

我子視圖上檢測到觸摸。我添加了另一個班的View作爲子視圖,並且此類包含背景上的UIImageView。對於例如

UIImageView *BGImageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"graphBG.png"]]; 
[BGImageView setContentMode:UIViewContentModeScaleAspectFill]; 
[BGImageView setFrame:CGRectMake(25, 365, 723, 390)]; 
[BGImageView setUserInteractionEnabled:YES]; 
[self.view sendSubviewToBack:BGImageView]; 
[self.view addSubview:BGImageView]; 
//[BGImageView release]; 
myGraph=[[MyGraphControllerView alloc]init]; 
myGraph.dataForPlot= [[NSMutableArray alloc]init]; 
for (int i=0; i<[hoursArry count]; i++) 
{ 
    NSMutableDictionary *dataDict=[[NSMutableDictionary alloc]init]; 
    [dataDict setObject:[dayArray objectAtIndex:i] forKey:@"x"]; 
    [dataDict setObject:[HoursArray objectAtIndex:i] forKey:@"y"]; 
    [myGraph.dataForPlot addObject:dataDict]; 
    [dataDict release]; 
} 
[myGraph.view setFrame:CGRectMake(25, 380, 723, 390)]; 
//[myGraph.view setBackgroundColor:[UIColor redColor]]; 
[self.view addSubview:myGraph.view]; 
} 

我已經添加了一個子視圖上GraphView,但沒有奏效。

請幫幫我。

回答

0

有一件事要確認:你爲什麼在UIImageView上啓用用戶交互? 將其設置爲禁用,以便它下面的視圖將成爲觸摸的響應者。請更新,如果它不工作,因爲我剛剛閱讀你的3行代碼&你可能有一些其他問題,可能不清楚從這裏。

0
//add gesture to mapview-for single touch 
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SLideTheView:)]; 
[touchableView addGestureRecognizer:tap]; 
tap.numberOfTapsRequired = 1; 

我會建議去姿勢爲需要觸摸的視圖進行檢測。

0

您正在檢查是否觸摸某個視圖名爲self.transView