我面临一个相关的问题UITouch
。我不知道为什么它不与 if 案例一起使用。
这是代码:
- (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
在 background 中。例如
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
但它不起作用。
请帮我。