ios uiviewcontroller怎么实现触摸事件
1个回答
展开全部
ios uiviewcontroller处理触摸事件的方法是:
在UIViewController的子类中重写以下几个函数:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
当手指接触到屏幕时触发
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
当手指在屏幕上滑动时
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
当手指滑动一段后离开屏幕时
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
当有系统事件发生要取消触摸事件时
从(UIEvent *)event中提取所有触摸事件
UITouch *touch = [[event allTouches]anyObject];
取得触摸事件对应的NSView
[touch view];
取得触摸事件对应NSView的座标
CGPoint touchLocation = [touch locationInView:self.view];
在UIViewController的子类中重写以下几个函数:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
当手指接触到屏幕时触发
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
当手指在屏幕上滑动时
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
当手指滑动一段后离开屏幕时
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
当有系统事件发生要取消触摸事件时
从(UIEvent *)event中提取所有触摸事件
UITouch *touch = [[event allTouches]anyObject];
取得触摸事件对应的NSView
[touch view];
取得触摸事件对应NSView的座标
CGPoint touchLocation = [touch locationInView:self.view];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询