多点触控乃苹果公司带给世界的创新之首,作为移动开发者,熟练掌握多点触控开发技能很有必要。
处理触摸的四个方法:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event //首次在屏幕上检测到触摸时调用
{
NSLog(@"touchesBegan");
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event //如果触摸移动到了新的位置则会调用此方法
{
NSLog(@"touchesMoved");
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event //当触摸离开屏幕调用此方法
{
NSLog(@"touchesEnded");
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event //如系统决定取消此次触摸,那可能就不调用touchesEnded方法了,在这种情况下会调用touchesCancelled方法
{
NSLog(@"touchesCancelled");
}
快速点击屏幕,Debug窗口显示
2014-01-13 22:47:10.121 bbsTouch[593:70b] touchesBegan
2014-01-13 22:47:10.125 bbsTouch[593:70b] touchesEnded
2014-01-13 22:47:10.238 bbsTouch[593:70b] touchesBegan
2014-01-13 22:47:10.239 bbsTouch[593:70b] touchesEnded
2014-01-13 22:47:10.242 bbsTouch[593:70b] touchesBegan
2014-01-13 22:47:10.244 bbsTouch[593:70b] touchesEnded
点击并在屏幕上拖动,Debug窗口显示
2014-01-13 22:48:44.148 bbsTouch[593:70b] touchesBegan
2014-01-13 22:48:44.163 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.195 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.211 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.229 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.249 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.281 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.314 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.330 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.347 bbsTouch[593:70b] touchesMoved
2014-01-13 22:48:44.821 bbsTouch[593:70b] touchesEnded
touchesMoved可能不会在触摸队列中产生,然而,touchesBegan事件之后,总会产生touchesEnded或touchesCancelled事件。
转载请注明原著:http://blog.csdn.net/marvindev
下一篇介绍 iOS开发笔记之多点触控(二) 开启多点触控的方法