重写 UIView
touchesBegan
touchesMoved
touchesEnded
//两个手指 init
self.multipleTouchEnabled=YES;
//单击和双击
UITouch *touch=[touches anyObject];
NSUInteger tapcount=touch.tapCount;
if(tapcount==1)
{
[self performSelector:@selector(singlefuntion) withObject:nil afterDelay:0.5];//延时调用
}
else if(tapcount==2)
{
[NSObject cancelPreviousPerFormRequestsWithTarget:self selector:@selector(singlefuntion) object:nil];
[self doublefuntion];
}
//触摸的点坐标
CGPoint point=[touch locationInView:myview];
//移动视图
UITouch *touch=[touches anyObject];
CGPoint point=[touch locatonInView:self];//得到触摸点
CGRect frame=movieView.frame; //要移动的视图位置
frame.origin=point; //触摸位置给框架
movieView.frame=frame; //框架给
//捏合手势的识别
NSArray *toucharr=[touches allObjects];
UItouch *fisrttouch=[toucharr obejctAtIndex:0];
UItouch *secondtouch=[toucharr obejctAtIndex:1];
CGpoint point1=[firsttouch locationInView:self];
CGpoint point2=[secondtouch locationInView:self];
((x1-x2)的平方+(y1-y2)平方)开方
double distance=sqrt(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2));
float subValue=distance-lastValue;
if(subValue>0)
{
NSLog(@"放大");
}
else
{
NSLog(@"缩小");
}
lastValue=distance;
/////////////////下面的用在控制器中
/////////////////////////didloadview
/////单击
UITapGestureRecognizer *tap=[UITapGestureRecognizer alloc]initWithTargetself action:@selector(tap:)];
[self.view addGestureRecognizer:tap];
//双击
tap.numberOfTapsRequired=2;
[self addGestureRecognizer:tap];
//区分单击和双击
[singtap requireGestureRecongnizerToFail:doubletap];
//向上轻扫
UISwipeGestureRecognizer *swipe=[UISwipeGestureRecognizer alloc]initWithTarget:self actio:@selector(swipe:)];
swipe.direction=UISwipeGestureRecognizerDirectionUp;//默认不写是向右轻扫
[self.view addGestureRecongnizer:swipe];
//平移手势 (滑动)
UIPanGestureRecngnizer *pan=[UIPanGestureRecngnizer alloc]initWithTarget:self action:@selector(pan:)];
[self.view addGestureRecngnizer:pan];
-(void)pan:(UIPanGestureRecngnizer *)_pan
{
CGPoint point=[_pan locationInView:self.view];
tempView.center=point;
}
//长按手势
UILongPressGestureRecognizer *longpress=[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
longpress.minimumPressDuration=3;
[self.view addGestureRecongnizer:longpress];
-(void)longPress:(UILongPressGestureRecognizer *)_longPress
{
NSLog(@"long %u",[_longPress state]);
}
//旋转手势
UIRotationGestureRecognizer *rotatio=[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selecttor(rotation)];
[self.view addGestureRecongnizer:rotation];
-(void)rotationAction:(UIRotationGestureRecognizer *)rotation
{
NSLog(@"%f",rotation.rotation);
}