利用touches方法拖动视图移动
2015-11-21 11:26
281 查看
拖动视图
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"摸我了");
self.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 /255.0 blue:arc4random() % 256 /255.0 alpha:1];
//获得当前触摸的点,touches内只有一个触摸对象
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
NSLog(@"%f, %f", point.x,point.y);
self.firstPoint = point;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"移动了");
//获得当前触摸的点,touches内只有一个触摸对象
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
NSLog(@"%f, %f", point.x,point.y);
self.center = CGPointMake(self.center.x + point.x - self.firstPoint.x , self.center.y + point.y - self.firstPoint.y);
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"摸我了");
self.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 /255.0 blue:arc4random() % 256 /255.0 alpha:1];
//获得当前触摸的点,touches内只有一个触摸对象
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
NSLog(@"%f, %f", point.x,point.y);
self.firstPoint = point;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"移动了");
//获得当前触摸的点,touches内只有一个触摸对象
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
NSLog(@"%f, %f", point.x,point.y);
self.center = CGPointMake(self.center.x + point.x - self.firstPoint.x , self.center.y + point.y - self.firstPoint.y);
}
相关文章推荐
- webrtc ICE rfc5245笔记
- sublime 设置缩进
- 一天当中最好的洗头时间
- 半平面求交——点在凸包外
- Pillow依赖库安装
- introduction to computer vision
- 自动生成项目的Makefile文件
- 轻松学习C#的预定义数据类型
- FTGL在OpenGL下显示中文
- 解析html 生成word文档
- ngxin proxy_set_header Host X-Forwarded-For
- 图片数组形成动画(UIImageView)
- Zookeeper 注册中心解析
- Unreal Engine 4 蓝图脚本学习 添加输入映射----实现冲刺和望眼镜效果 (3)
- RF Test and Measurement-1
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- 手势
- 单片机学习之点亮LED小灯
- 不用算术运算符实现两个数的加法
- Android之SharePreferences