0
我有一個很大的問題,因爲最近2天。我正在使用支持多點觸控的視圖。我的UIViewController有8-10 imageview。我想單獨檢測每個視圖的觸摸,但一次檢測多個視圖。在所有圖像視圖上檢測到觸摸,但問題在這裏 -第二個UITouch事件觸發器第一個UITouch事件爲什麼?
假設我點擊圖像視圖並按住此圖像視圖,然後點擊另一個圖像視圖,第二個圖像視圖被檢測到觸摸成功,但它也觸發先前觸摸並按住的第一個圖像視圖。但我不想要它。所以請任何人幫助我。代碼級別的幫助表示讚賞。
注意:我的UIViewController也實現了用於滑動目的的TouchesMoved方法。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for(UITouch *touch in event.allTouches) {
if(CGRectContainsPoint([imView1 frame], [touch locationInView:self.view])){
NSLog(@"imView 1 touched");
}
if(CGRectContainsPoint([imView2 frame], [touch locationInView:self.view])){
NSLog(@"imView 2 touched");
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for(UITouch *touch in event.allTouches) {
if(CGRectContainsPoint([imView1 frame], [touch locationInView:self.view])){
NSLog(@"imView 1 touch moved");
}
if(CGRectContainsPoint([imView2 frame], [touch locationInView:self.view])){
NSLog(@"imView 2 touch moved");
}
}
}
感謝您的快速反應。你能解釋一下嗎?它將如何工作? – user413866 2010-08-07 16:15:38
而不是使用UIImageView,創建一個新的NSObject和子類UIImageView,使其看起來像 @interface MyImageView:UIImageView {} @ end ,並且在實現(.m文件)中,您將擁有@implementation,然後觸摸代碼。在子類中,你可以做任何你需要做的事情,如果你需要調用父類的東西,那麼你可以做到這一點。發送觸摸到父母,你會做類似 [self.nextResponder touchesMoved:touches withEvent:event]; – AtomRiot 2010-08-07 17:29:39
感謝您的建議。如果你給我一個源代碼示例,那麼它會保存我的2天。請給我一個示例項目,它有超過2個imageview,並分別檢測每個圖像視圖上的滑動,並解決了這個問題。再次感謝您的回覆。 – user413866 2010-08-09 17:08:34