我在我的应用中使用此代码来识别特定UIView
上的触摸和拖动,
现在我有一个问题,如果我进行触摸并立即拖动touchesMoved
只调出3-4次并停止然后touchesCancelled
调用,但如果我触摸屏幕等一秒钟,然后每次手指移动时拨打touchesMoved
。
我在iphone 4s上测试了它,并且使用这个设备它完美无缺,在ipod4中仍然存在问题。两个设备都是5.01。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray* touchArray = [touches allObjects];
UITouch* touch = [touchArray objectAtIndex:0];
CGPoint point = [touch locationInView:self.view];
UIView *tmp = [self.view hitTest:point withEvent:event];
if (tmp == volumeViewBackground) {
//do something
}else {
NSLog(@"err");
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray* touchArray = [touches allObjects];
UITouch* touch = [touchArray objectAtIndex:0];
CGPoint point = [touch locationInView:self.view];
UIView *tmp = [self.view hitTest:point withEvent:event];
if (tmp == volumeViewBackground) {
//do something
}else {
NSLog(@"err");
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"error");
}
答案 0 :(得分:0)
根据UIResponder Class Reference尝试拨打super
。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan: touches withEvent: event];
NSArray* touchArray = [touches allObjects];
UITouch* touch = [touchArray objectAtIndex:0];
CGPoint point = [touch locationInView:self.view];
UIView *tmp = [self.view hitTest:point withEvent:event];
if (tmp == volumeViewBackground) {
//do something
}else {
NSLog(@"err");
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved: touches withEvent: event];
NSArray* touchArray = [touches allObjects];
UITouch* touch = [touchArray objectAtIndex:0];
CGPoint point = [touch locationInView:self.view];
UIView *tmp = [self.view hitTest:point withEvent:event];
if (tmp == volumeViewBackground) {
//do something
}else {
NSLog(@"err");
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesCancelled: touches withEvent: event];
NSLog(@"error");
}