0
我使用自定義UIImageview檢測觸摸?但我無法檢測到特定的imageview觸摸。我如何檢測自定義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"];
}
}
在這段代碼中,我沒有檢測到觸摸?請幫助我?
無法自定義視圖的檢測。
使用自定義的UIImageView,但它繼承了原有的UIImageView的/子? –
我不明白這個標籤是關於這裏的...爲什麼不只是測試圖像和image2? – Eiko
我將2個UIImageview(這些都是自定義不在.XIB中)添加到另一個ImageView。該imageview被添加到主視圖像:[self.view addSubView:imageView]; – sreenivas