Iphone 触摸不检测?
我正面临一个与UITouch相关的问题。我不知道为什么它不符合if案例 代码如下:Iphone 触摸不检测?,iphone,ios,uitouch,Iphone,Ios,Uitouch,我正面临一个与UITouch相关的问题。我不知道为什么它不符合if案例 代码如下: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if([touch view] == self.transView) { NSLog(@"Began"); CGPoint startLocatio
- (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;
}
}
我正在检测子视图上的触摸。我添加了另一个类的视图作为子视图,这个类在后台包含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上添加了一个子视图,但它不起作用
请帮助我。有一件事需要确认:为什么要在UIImageView上启用用户交互?? 将其设置为InAction disable,使其下方的视图现在成为触摸的响应者。请更新,如果它不工作,因为我刚刚读了你的3行代码&你可能有一些其他问题,这可能是不清楚从这里
//add gesture to mapview-for single touch
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SLideTheView:)];
[touchableView addGestureRecognizer:tap];
tap.numberOfTapsRequired = 1;
我建议对需要触摸才能检测到的视图使用手势。您正在检查它是否正在触摸名为self.transView的视图