use*_*607 5 objective-c zooming uiscrollview panning ios
我有一个包含 UIImageView 的 UIScrollView。UIScrollView 允许缩放和平移 UIImageView。
问题是我每次都想知道手指的运动,我试图用 touchesMoved 方法来捕捉事件。但它不起作用,尽管 touchesBegan 和 touchesEnded 被正确调用。
实际上,如果手指移动非常小,并且 UIScrollView 没有开始平移,则会调用 touchesMoved。在 UIScrollView 开始移动的那一刻,事件停止被调用。
有人知道是什么问题以及如何解决吗?我想也许里面的 UIImageView 正在捕捉事件或类似的东西。
创建UIScrollView类的子类并重写touchesBegan:和其他触摸方法,如下所示:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// If not dragging, send event to next responder
if (!self.dragging)
{
[self.nextResponder touchesBegan: touches withEvent:event];
}
else
{
[super touchesEnded: touches withEvent: event];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// If not dragging, send event to next responder
if(!self.dragging)
{
[self.nextResponder touchesBegan: touches withEvent:event];
}
else
{
[super touchesEnded: touches withEvent: event];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// If not dragging, send event to next responder
if (!self.dragging)
{
[self.nextResponder touchesBegan: touches withEvent:event];
}
else
{
[super touchesEnded: touches withEvent: event];
}
}
Run Code Online (Sandbox Code Playgroud)