我正在使用自定义 UIImageview 来检测触摸?但我无法检测到对该特定图像视图的触摸。
-(void)viewDidLoad {
[super viewDidLoad];
mainView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 300, 100, 100)];
image.image = [UIImage imageNamed:@"CyanSquare.png"];
image2 = [[UIImageView alloc] initWithFrame:CGRectMake(150, 600, 100, 100)];
image2.image = [UIImage imageNamed:@"CyanSquare.png"];
image.tag = 1;
image2.tag = 2;
[self.mainView addSubview:image];
[self.mainView addSubview:image2];
[self.view addSubview:mainView];
}
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [[event allTouches] anyObject];
[super touchesBegan:touches withEvent:event];
if ([touch view] == [image viewWithTag:1]) {
NSLog(@"touch beggin 1");
mainView.image = [UIImage imageNamed:@"VideoBkGround.png"];
}
if ([touch view] == [image2 viewWithTag:2])
{
NSLog(@"touch beggin 2");
mainView.image = [UIImage imageNamed:@"VideoRunning.png"];
}
}
在这段代码中我没有检测到触摸?请帮助我?
如果没有自定义视图,它会被检测到。