[英]touchesMoved detection doesn't work properly
在我的應用程序中,我使用touchesMoved方法檢測向左/向右滑動。 當用戶連續向左和向右滑動時,圖像動畫會自動更新。 我能夠檢測到滑動動作,但是有時當我開始連續向左和向右滑動時,屏幕無法檢測到觸摸移動事件。
在滑動區域中,我放置了一個隱藏按鈕和幾個用於動畫的ImageView。 我想知道為什么會發生。請幫助我。
謝謝。
碼:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint newLocation = [touch locationInView:self.view];
CGPoint oldLocation = [touch previousLocationInView:self.view];
if(newLocation.x-oldLocation.x>0){
swipe_direction = 1;
//NSLog(@"left");
}
else{
swipe_direction = 2;
//NSLog(@"right");
}
if(swipe_direction == 1){
//animate images
}
else if(swipe_direction == 2){
//animate images
}
}
touchesMoved
僅在視圖的空白部分進行檢測。 因此,它不會檢測到您使用過的對象。
將SwipeGestureRecognizer放置在視圖上方,然后從那里使用它。
您是否考慮過使用SwipeGestureRecognizer而不是touchesMoved?
檢查文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.