-
触屏事件
-
-
-
- - (void)touchesBegan:(NSSet *)touches
-
- withEvent:(UIEvent *)event
-
- {
-
- messageLabel.text = @”Touches Began”;
-
- [self updateLabelsFromTouches:touches];
-
- }
-
-
- - (void)touchesCancelled:(NSSet *)touches
-
- withEvent:(UIEvent *)event
-
- {
-
- messageLabel.text = @”Touches Cancelled”;
-
- [self updateLabelsFromTouches:touches];
-
- }
-
-
- - (void)touchesEnded:(NSSet *)touches
-
- withEvent:(UIEvent *)event
-
- {
-
- messageLabel.text = @”Touches Stopped.”;
-
- [self updateLabelsFromTouches:touches];
-
- }
-
-
- - (void)touchesMoved:(NSSet *)touches
-
- withEvent:(UIEvent *)event
-
- {
-
- messageLabel.text = @”Drag Detected”;
-
- [self updateLabelsFromTouches:touches];
-
- }
-
-
-
- - (void)touchesBegan:(NSSet *)touches
-
- withEvent:(UIEvent *)event
-
- {
-
- UITouch *touch = [touches anyObject];
-
- gestureStartPoint = [touch locationInView:self.view];
-
- }
-
-
- - (void)touchesMoved:(NSSet *)touches
-
- withEvent:(UIEvent *)event
-
- {
-
- UITouch *touch = [touches anyObject];
-
- CGPoint currentPosition = [touchlocationInView:self.view];
-
- CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
-
- CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
-
- if(deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance)
-
- {
-
- label.text = @”Horizontal swipe detected”;
-
- [self performSelector:@selector(eraseText)
-
- withObject:nilafterDelay:2];
-
- }
-
- else if (deltaY >= kMinimumGestureLength &&
-
- deltaX <= kMaximumVariance)
-
- {
-
- label.text = @”Vertical swipe detected”;
-
- [selfperformSelector:@selector(eraseText)withObject:nilafterDelay:2];
-
- }
-
- }
-
-
-
- - (void)singleTap
-
- {
-
- singleLabel.text = @”Single Tap Detected”;
-
- [selfperformSelector:@selector(eraseMe:)
-
- withObject:singleLabel
-
- afterDelay:1.6f];
-
- }
-
-
- - (void)doubleTap
-
- {
-
- doubleLabel.text = @”Double Tap Detected”;
-
- [selfperformSelector:@selector(eraseMe:)
-
- withObject:doubleLabel
-
- afterDelay:1.6f];
-
- }
-
-
- - (void)tripleTap
-
- {
-
- tripleLabel.text = @”Triple Tap Detected”;
-
- [selfperformSelector:@selector(eraseMe:)
-
- withObject:tripleLabel
-
- afterDelay:1.6f];
-
- }
-
-
- - (void)quadrupleTap
-
- {
-
- quadrupleLabel.text = @”Quadruple Tap Detected”;
-
- [selfperformSelector:@selector(eraseMe:)
-
- withObject:quadrupleLabel
-
- afterDelay:1.6f];
-
- }
-
- - (void)eraseMe:(UITextField *)textField
-
- {
-
- textField.text = @"";
-
- }
-
- - (void)touchesBegan:(NSSet *)touches
-
- withEvent:(UIEvent *)event
-
- {
-
- UITouch *touch = [touches anyObject];
-
- NSUInteger tapCount = [touch tapCount];
-
- switch (tapCount)
-
- {
-
- case 1:
-
- [selfsingleTap];
-
- break;
-
- case 2:
-
- [selfdoubleTap];
-
- break;
-
- case 3:
-
- [selftripleTap];
-
- break;
-
- case 4:
-
- [selfquadrupleTap];
-
- break;
-
- default:
-
- break;
-
- }
-
- }
-
-
-
-
-
-
- - (void)eraseLabel
-
- {
-
- label.text = @"";
-
- }
-
-
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-
- {
-
- if([touches count] ==2)
-
- {
-
- NSArray *twoTouches = [touchesallObjects];
-
- UITouch *first = [twoTouchesobjectAtIndex:0];
-
- UITouch *second = [twoTouchesobjectAtIndex:1];
-
- initialDistance = distanceBetweenPoints(
-
- [first locationInView:self.view], [secondlocationInView:self.view]);
-
- }
-
- }
-
-
- - (void)touchesMoved:(NSSet *)touches
-
- withEvent:(UIEvent *)event
-
- {
-
- if ([touches count] == 2)
-
- {
-
- NSArray *twoTouches = [touchesallObjects];
-
- UITouch *first = [twoTouchesobjectAtIndex:0];
-
- UITouch *second = [twoTouchesobjectAtIndex:1];
-
- CGFloat currentDistance =distanceBetweenPoints(
-
- [first locationInView:self.view],[secondlocationInView:self.view]);
-
- if (initialDistance ==0)
-
- {
-
- initialDistance = currentDistance;
-
- }
-
- else if (currentDistance - initialDistance > kMinimumPinchDelta)
-
- {
-
- label.text = @”Outward Pinch”;
-
- [selfperformSelector:@selector(eraseLabel)
-
- withObject:nil
-
- afterDelay:1.6f];
-
- }
-
- else if (initialDistance - currentDistance > kMinimumPinchDelta)
-
- {
-
- label.text = @”Inward Pinch”;
-
- [selfperformSelector:@selector(eraseLabel)
-
- withObject:nil
-
- afterDelay:1.6f];
-
- }
-
- }
-
- }
-
-
- - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
-
- {
-
- initialDistance = 0;
-
- }
-
-
- - (void)eraseLabel
-
- {
-
- label.text = @"";
-
- }
-
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-
- {
-
- UITouch *touch = [touches anyObject];
-
- CGPoint point = [touch locationInView:self.view];
-
- lastPreviousPoint = point;
-
- lastCurrentPoint = point;
-
- lineLengthSoFar = 0.0f;
-
- }
-
- - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
-
- {
-
- UITouch *touch = [touches anyObject];
-
- CGPoint previousPoint = [touchpreviousLocationInView:self.view];
-
- CGPoint currentPoint = [touch locationInView:self.view];
-
-
- CGFloat angle = angleBetweenLines(lastPreviousPoint,
-
- lastCurrentPoint,previousPoint,currentPoint);
-
-
-
-
- if (angle >= kMinimumCheckMarkAngle &&
-
- angle <= kMaximumCheckMarkAngle &&
-
- lineLengthSoFar > kMinimumCheckMarkLength)
-
- {
-
- label.text = @”Checkmark”;
-
- [selfperformSelector:@selector(eraseLabel)
-
- withObject:nil
-
- afterDelay:1.6];
-
- }
-
-
- lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
-
- lastPreviousPoint = previousPoint;
-
- lastCurrentPoint = currentPoint;
-
- }
-
-
-
-
-
- #import <CoreGraphics/CoreGraphics.h>
-
- CGFloat distanceBetweenPoints (CGPoint first,CGPoint second);
-
- CGFloat angleBetweenPoints(CGPoint first, CGPoint second);
-
- CGFloat angleBetweenLines(CGPoint line1Start,CGPoint line1End, CGPoint line2Start,CGPoint lin2End);
-
-
- #include ”CGPointUtils.h”
-
- #include <math.h>
-
- #define pi 3.14159265358979323846
-
- #define degreesToRadian(x) (pi * x / 180.0)
-
- #define radiansToDegrees(x) (180.0 * x / pi)
-
- CGFloat distanceBetweenPoints (CGPoint first,CGPoint second)
-
- {
-
- CGFloat deltaX = second.x - first.x;
-
- CGFloat deltaY = second.y - first.y;
-
- return sqrt(deltaX*deltaX + deltaY*deltaY );
-
- };
-
- CGFloat angleBetweenPoints(CGPoint first, CGPoint second)
-
- {
-
- CGFloat height = second.y - first.y;
-
- CGFloat width = first.x - second.x;
-
- CGFloat rads = atan(height/width);
-
- returnradiansToDegrees(rads);
-
-
- }
-
- CGFloat angleBetweenLines(CGPoint line1Start,CGPoint line1End, CGPoint line2Start,CGPoint line2End)
-
- {
-
- CGFloat a = line1End.x - line1Start.x;
-
- CGFloat b = line1End.y - line1Start.y;
-
- CGFloat c = line2End.x - line2Start.x;
-
- CGFloat d = line2End.y - line2Start.y;
-
- CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));
-
- returnradiansToDegrees(rads);
-
- }
-
相关阅读:
json字符串和xml的 比较
Python基础第十三天——sys模块、logging模块、json模块、pickle模块
Python基础第十二天——模块的分类、时间模块、随机数模块、摘要算法模块、os模块、时间形式轮换
Python基础第十一天——内置函数的补充、内置函数与lambda、递归
Python基础第九天——迭代对象、 迭代器对象、生成器、三元表达式列表解析、生成器表达式
Python基础第八天——无参装饰器、有参装饰器
Python基础第七天——global与nonlocal、闭包函数、装饰器
Python基础第六天——函数的使用、函数的参数、函数的返回值、函数的嵌套、命名空间、作用域、函数对象
Python基础第五天——字符编码、文件处理、函数的使用
Python基础第四天——字典、布尔值、集合
-
原文地址:https://www.cnblogs.com/W-Kr/p/5095326.html
Copyright © 2020-2023
润新知