-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan");
//手指在屏幕上每一次触摸都会产生一个触摸事件
//这些事件会保存这个NSSet 类型的 touches里
//我们可以取出这个事件
UITouch * touch = [touches anyObject];
[UIView animateWithDuration:0.3 animations:^{
imageView.center = [touch locationInView:self.window];
}];
NSLog(@"window:%@",touch.window);
NSLog(@"view:%@",touch.view);
NSLog(@"phase:%id",touch.phase);
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesEnded");
//可以在这里不使用任何一个事件,只去写我们自己的方法
[UIView animateWithDuration:0.3 animations:^{
imageView.center = CGPointMake(160, 300);
}];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//那么,手指只要在屏幕有偏移那么就调用一次这个方法
NSLog(@"touchesMove");
UITouch * touch = [touches anyObject];
NSLog(@"view:%@",touch.view);
if (touch.view == imageView && touch.phase == UITouchPhaseMoved) {
imageView.center = [touch locationInView:self.window];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
//程序运行过程中,进来电话,短信,推送等优先级比较高的事件
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。