IOS学习之——UITouch 控件的学习
来源:互联网 发布:大数据安全保密制度 编辑:程序博客网 时间:2024/06/05 16:48
//***************************** UITouch 属性 ******************************** //
触摸产生时所处的窗口 @property(nonatomic,readonly,retain) UIWindow *window; 触摸产生时所处的视图 @property(nonatomic,readonly,retain) UIView *view; 短时间内点按屏幕的次数,可以根据tapCount判断单击、双击或更多的点击 @property(nonatomic,readonly) NSUInteger tapCount; 记录了触摸事件产生或变化时的时间,单位是秒 @property(nonatomic,readonly) NSTimeInterval timestamp; 当前触摸事件所处的状态 @property(nonatomic,readonly) UITouchPhase phase;
//***************************** UITouch 方法 ******************************** //
■ - (CGPoint)locationInView:(UIView *)view; //当前触摸的位置➢ 返回值表示触摸在view上的位置➢ 这里返回的位置是针对view的坐标系的(以view的左上角为原点(0, 0))➢ 调用时传入的view参数为nil的话,返回的是触摸点在UIWindow的位置➢ • - (CGPoint)previousLocationInView:(UIView *)view; // 移动的时候是从之前的那个点 移动到下一个点➢ 该方法记录了前一个触摸点的位置
//***************************** UITouch 例子 ******************************** //
-(void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event{
return;NSLog(@"%s",__func__);// 获取当前触摸点的UITouch对象UITouch *touch = [touches anyObject];// 触摸点 所在的viewNSLog(@"%@",touch.view);// tapCount 点击的次数NSLog(@"%ld",touch.tapCount);// 获取当前 触摸的位置
warning 传一个nil 获取的触摸点的位置是在windows上去
CGPoint touchPosition = [touch locationInView:touch.view];NSLog(@"%@",NSStringFromCGPoint(touchPosition));
}
-(void)touchesMoved:(NSSet )touches withEvent:(UIEvent )event{
//NSLog(@”%s”,func);
// 获取当前触摸点的UITouch对象
UITouch *touch = [touches anyObject];
//获取 当前触摸的位置CGPoint current = [touch locationInView:touch.view];//获取 触摸前的位置CGPoint previous = [touch previousLocationInView:touch.view];NSLog(@"触摸前的点: %@ 当前触摸点:%@",NSStringFromCGPoint(previous), NSStringFromCGPoint(current)); //********** 可以拖动的按钮 悬浮的按钮 能应用到游戏中 // 改变位置CGPoint center = self.center;center.x += current.x - previous.x;center.y += current.y - previous.y;self.center = center;
}
0 0
- IOS学习之——UITouch 控件的学习
- IOS学习之——UItouch的相关使用
- IOS学习 UITouch基础学习
- IOS学习之——UIEvent 控件的学习
- 我的iOS学习历程 - UITouch(触摸反应)
- iOS控件 ----- UITouch相关
- IOS学习 触摸和手势UITouch 捏合
- IOS学习之控件
- IOS开发之UITouch
- IOS开发之UITouch
- iOS开发之UITouch
- iOS学习笔记之-使用UITouch来根据手指位置移动图片
- iOS触摸手势——UITouch
- iOS触摸手势——UITouch
- IOS学习 触摸和手势UITouch 单击双击、移动视图
- IOS学习之——UIRefreshControl下拉刷新控件
- IOS控件学习之UILabel
- 学习ios之基础控件
- Servlet的一些细节
- WPF之Validation
- 微软云+Servlet实现图片上传接口
- fedora 22 '/sbin/rcvboxdrv setup'
- 最简单的算法-冒泡排序
- IOS学习之——UITouch 控件的学习
- 【Audio】AudioContext中的ScriptProcessorNode接口和AudioProcessingEvent接口详解
- Linux多线程同步——互斥锁
- QT:配置qtcreator交叉环境
- Android小项目:记事本
- Sverlet生命周期和工作机制
- 阻抗控制和计算
- Apache Hadoop2.6.2 小集群搭建
- QT:QT编译时 qmake错误