[英]Touch not detecting?
I am facing a problem related UITouch
. 我面临与
UITouch
有关的问题。 I don't the reason why It's not going with the if case. 我不是为什么不与if一起使用的原因。
Here is the code: 这是代码:
- (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;
}
}
I am detecting touch on SubView. 我在SubView上检测到触摸。 I added another class's
View
as subview and this class contains UIImageView
on background . 我添加了另一个类的
View
作为子视图,并且该类在background上包含UIImageView
。 For eg 例如
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];
}
I have already added a subview on GraphView
but it did not work. 我已经在
GraphView
上添加了一个子视图,但是它不起作用。
Please help me. 请帮我。
One thing to confirm: Why are you enabling the user interaction on UIImageView?? 需要确认的一件事:为什么要在UIImageView上启用用户交互? Set it's intraction disable so that view below it will now be the responder for touches.
将其设置为禁止吸引,以使其下方的视图现在成为触摸的响应者。 Kindly update if it doesn't work as i just read your 3 lines of code & you might have some other problem which might be not clear from here.
请更新,如果它不起作用,因为我只是读了您的3行代码,您可能还有其他一些问题,可能无法从此处清除。
//add gesture to mapview-for single touch
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SLideTheView:)];
[touchableView addGestureRecognizer:tap];
tap.numberOfTapsRequired = 1;
I would suggest to go with gesture for the view that needs touch to be detected. 我建议使用手势来检测需要触摸的视图。
您正在检查是否正在触摸名为self.transView的某个视图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.