标签:last integer 需要 win 指定 code dev float gre
// 获取任意一个触摸对象
UITouch *touch = [touches anyObject];
// 获取任意一个触摸对象
UITouch *touch = [[event allTouches] anyObject];
// 获取指定的 view 触摸对象
UITouch *touch = [[event touchesForView:myView] anyObject];
// 获取指定的 window 触摸对象
UITouch *touch = [[event touchesForWindow:self.view.window] anyObject];
// 设置接收多点触摸
/*
默认为 NO,即视图默认不接收多点触摸
*/
self.view.multipleTouchEnabled = YES;
// 获取触摸窗口
UIWindow *touchWindow = touch.window;
// 获取触摸视图
UIView *touchView = touch.view;
// 获取触摸手势
NSArray *touchGesture = touch.gestureRecognizers;
// 获取触摸次数
NSUInteger tapCount = touch.tapCount;
// 获取触摸时间
NSTimeInterval timestamp = touch.timestamp;
// 获取触摸状态
/*
UITouchPhaseBegan, // whenever a finger touches the surface. 触摸开始
UITouchPhaseMoved, // whenever a finger moves on the surface. 接触点移动
UITouchPhaseStationary, // whenever a finger is touching the surface but hasn't moved
// since the previous event. 接触点无移动
UITouchPhaseEnded, // whenever a finger leaves the surface. 触摸结束
UITouchPhaseCancelled, // whenever a touch doesn't end but we need to stop tracking
// (e.g. putting device to face) 触摸取消
*/
UITouchPhase touchPhase = touch.phase;
// 获取触摸位置
// 上次触摸点的位置
CGPoint lastPoint = [touch previousLocationInView:self.view];
// 当前触摸点的位置
CGPoint currentPoint = [touch locationInView:self.view];
// 获取触摸半径
CGFloat majorRadius = touch.majorRadius;
CGFloat majorRadiusTolerance = touch.majorRadiusTolerance;
// 触摸开始,重写 UIResponder 中定义的方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
// 触摸移动,重写 UIResponder 中定义的方法
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
}
// 触摸结束,重写 UIResponder 中定义的方法
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
// 触摸取消,重写 UIResponder 中定义的方法
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
}
// 触摸移动
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// 获取触摸对象
UITouch *touch = [touches anyObject];
UIView *tapView = touch.view;
// 获取触摸点位置
CGPoint lastPoint = [touch previousLocationInView:self.view];
CGPoint currentPoint = [touch locationInView:self.view];
// 改变视图中心坐标
CGPoint tapViewCenter = tapView.center;
tapViewCenter.x += currentPoint.x - lastPoint.x;
tapViewCenter.y += currentPoint.y - lastPoint.y;
tapView.center = tapViewCenter;
}
// 触摸结束
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
// 单击
if (touch.tapCount == 1) {
// 响应单击触摸事件
[self performSelector:@selector(singleTapClick) withObject:nil afterDelay:0];
}
// 双击
else if (touch.tapCount == 2) {
// 取消单击触摸响应事件
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapClick) object:nil];
// 响应双击触摸事件
[self performSelector:@selector(doubleTapClick) withObject:nil afterDelay:0];
}
}
// 单击触摸响应事件处理
- (void)singleTapClick {
self.view.backgroundColor = [UIColor greenColor];
}
// 双击触摸响应事件处理
- (void)doubleTapClick {
self.view.backgroundColor = [UIColor orangeColor];
}
标签:last integer 需要 win 指定 code dev float gre
原文地址:https://www.cnblogs.com/CH520/p/9413505.html