ios学习之基础 触摸事件5

//触摸和手势  
重写 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);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值