UI之把一个控件在屏幕内做任意拖拽并得到时时坐标
来源:互联网 发布:淘宝手机助手登陆失败 编辑:程序博客网 时间:2024/06/05 01:10
@interfaceViewController ()
{
UIView *_view;
UIImageView *_imageV;
}
@end
@implementationViewController
- (void)viewDidLoad {
[super viewDidLoad];
_view = [[UIView alloc]initWithFrame:CGRectMake(100,100, 100, 100)];
_view.backgroundColor = [UIColorpurpleColor];
[self.view addSubview:_view];
_imageV = [[UIImageViewalloc]initWithFrame:CGRectMake(100, 220, 100, 100)];
_imageV.image = [UIImage imageNamed:@"blue"];
//是否与用户交互 UIImageView默认是NO 想要交互设置为YES
_imageV.userInteractionEnabled = YES;
[self.view addSubview:_imageV];
}
//开始触摸
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//touches 触摸的集合
//当手指在屏幕上点击/滑动的时候都会生成触摸对象(UITouch)
//集合里面就一个touch对象,可以使用anyObject拿出来
UITouch *touch = [touches anyObject];
//拿到触摸的时间
NSTimeInterval time = touch.timestamp;
NSLog(@"touch时间:%f",time);
//点击多少次
NSUInteger num = touch.tapCount;
NSLog(@"第几次数:%ld",(unsignedlong)num);
//事件(触摸)处于什么状态
UITouchPhase phase = touch.phase;
/*
UITouchPhaseBegan,
UITouchPhaseMoved,
UITouchPhaseStationary,
UITouchPhaseEnded,
UITouchPhaseCancelled,
*/
//拿到当前touch的视图控件
UIView *view = touch.view;
NSLog(@"当前touch的控件:%@",view);
//previousLocationInView 拿到上一次touch的坐标
CGPoint lastPoint = [touchpreviousLocationInView:view];
//locationInView 拿到当前的touch的坐标
CGPoint locaPoint = [touchlocationInView:view];
NSLog(@"上一次坐标:%@ 当前坐标:%@",NSStringFromCGPoint(lastPoint),NSStringFromCGPoint(locaPoint));
}
//取消触摸(电话、短信....)
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
}
//结束触摸
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"触摸结束");
}
//移动触摸
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
UIView *view = touch.view;
NSLog(@"moved当前touch的控件:%@",view);
//previousLocationInView 拿到上一次touch的坐标
CGPoint lastPoint = [touchpreviousLocationInView:view];
//locationInView 拿到当前的touch的坐标
CGPoint locaPoint = [touchlocationInView:view];
NSLog(@"moved上一次坐标:%@ 当前坐标:%@",NSStringFromCGPoint(lastPoint),NSStringFromCGPoint(locaPoint));
//位移的距离
CGPoint point = CGPointMake(locaPoint.x-lastPoint.x, locaPoint.y - lastPoint.y);
if (view == self.view) {
NSLog(@"站住,不许动");
}else{
//通过偏移量重新设置view的center
view.center = CGPointMake(view.center.x+ point.x, view.center.y + point.y);
}
}
- UI之把一个控件在屏幕内做任意拖拽并得到时时坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android 得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- 一个控件在屏幕中拖拽到任意位置
- 如何得到一个控件相对于屏幕左上角的坐标
- (4.1.40.1)Android得到控件在屏幕中的坐标
- android 把控件放在屏幕任意位置
- ugui ui相对位置的计算,以及如何把ui限制在屏幕内
- UI之摇晃手机和触摸手势
- RStudio改变工作路径
- Android——httpPost方式网络互通信
- 蓝牙知识点
- 光照亮度调整(图像拼接之前)
- UI之把一个控件在屏幕内做任意拖拽并得到时时坐标
- 深刻理解Python中的元类(metaclass)
- 反射机制是什么?
- 杭电acm1398
- 牛客网 | 把二叉树打印成多行
- Python的爬虫框架 Scrapy
- Codeforces Round 580 D. Kefa and Dishes (状态压缩dp)
- sql server中,N''表示什么意思?
- Android之可伸缩的皮筋效果(贝塞尔曲线)的介绍