[英]Handling touches on Iphone
我在處理應用程序中的觸摸時遇到了一些問題。
我開始這樣設置:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *currentTouch = [[event allTouches] anyObject];
touchPoint = [currentTouch locationInView:self.view];
if (CGRectContainsPoint(image1.frame, touchPoint)) {
image1IsTouched = YES;
}
}
然后我將觸摸動作設置為:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *currentTouch = [[event allTouches] anyObject];
currentPoint = [currentTouch locationInView:currentTouch.view];
if(image1IsTouched == YES) {
image1.center = CGPointMake(currentPoint.x,currentPoint.y);
.....
}
}
現在,我在實際設備上嘗試了我的應用,這就是我注意到我的問題的地方。 當我用一根手指觸摸image1時,應用程序運行正常,每次我拖動手指時都會檢查碰撞。 當我在觸摸/拖動圖像時用另一根手指觸摸屏幕時,會出現問題。 我當前觸摸的圖像將跳到另一根手指。 我已經嘗試過[myView setMultipleTouchEnable:NO];
&在觸摸上使用NSArray
,然后將[touches count]
與觸摸進行比較,但無法正常工作。 有人可以告訴我如何將uiimageview設置為僅在單點觸摸時起作用。 謝謝。
首先,您應該使用UITouch *currentTouch = [touches anyObject];
獲取當前的觸摸。
其次,您應該檢查touches.count == 1
以確保屏幕上只有一根手指,如果一根手指以上,則忽略觸摸輸入,除非您想支持多點觸摸。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.