五种常用手势

- (void)loadView
{
    UIView *aView = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
    aView.backgroundColor = [UIColor whiteColor];
    self.view = aView;
    [aView release];
    _imageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 300, 400)];
    _imageView.userInteractionEnabled=YES;
    _imageView.image=[UIImage imageNamed:@"h1.jpeg"];
    [self.view addSubview:_imageView];
    [_imageView release];
    /*
     //轻触手势(单击,双击)
    UITapGestureRecognizer *tapCgr=nil;
    tapCgr=[[UITapGestureRecognizer alloc]initWithTarget:self
                                                  action:@selector(tap:)];
    tapCgr.numberOfTapsRequired=2;
    [_imageView addGestureRecognizer:tapCgr];
    [tapCgr release];
     
    //长按手势
    UILongPressGestureRecognizer *longGnizer=nil;
    longGnizer=[[UILongPressGestureRecognizer alloc]initWithTarget:self
                                                            action:@selector(longGo:)];
    [self.view addGestureRecognizer:longGnizer];
    [longGnizer release];
    
    //轻扫手势
    UISwipeGestureRecognizer *swi=nil;
    swi=[[UISwipeGestureRecognizer alloc]initWithTarget:self
                                                 action:@selector(swie:)];
    [self.view addGestureRecognizer:swi];
    [swi release];
    
   //旋转手势
    UIRotationGestureRecognizer *ro=nil;
    ro=[[UIRotationGestureRecognizer alloc]initWithTarget:self
                                                   action:@selector(roro:)];
    [self.view addGestureRecognizer:ro];
     [ro release];
      
     //捏合
    UIPinchGestureRecognizer *pin=nil;
    pin=[[UIPinchGestureRecognizer alloc]initWithTarget:self
                                                 action:@selector(pinp:)];
    [self.view addGestureRecognizer:pin];
    [pin release];
      */
    UIPanGestureRecognizer *pan=nil;
    pan=[[UIPanGestureRecognizer alloc]initWithTarget:self
                                               action:@selector(panp:)];
    [self.view addGestureRecognizer:pan];
    [pan release];
}
-(void)panp:(UIPanGestureRecognizer *)agre{
    CGPoint beginPoint;
    CGPoint endPoint;
    if (agre.state==UIGestureRecognizerStateBegan) {
        beginPoint=[agre locationInView:_imageView];
        
    }
    endPoint=[agre locationInView:_imageView];
    CGFloat dx=endPoint.x-beginPoint.x;
    CGFloat dy=endPoint.y-beginPoint.y;
    _imageView.center=CGPointMake(_imageView.center.x+dx, _imageView.center.y+dy);
}
-(void)pinp:(UIPinchGestureRecognizer *)agre{
    _imageView.transform=CGAffineTransformMakeScale(agre.scale, agre.scale);
}
-(void)roro:(UIRotationGestureRecognizer *)ager{
    _imageView.transform=CGAffineTransformMakeRotation(ager.rotation);
    NSLog(@"%s",__func__);
}
-(void)swie:(UISwipeGestureRecognizer *)Ager{
    _imageView.image=[UIImage imageNamed:@"h2.jpeg"];
    NSLog(@"%s",__func__);
}
-(void)longGo:(UILongPressGestureRecognizer *)aGer{
    if (aGer.state==UIGestureRecognizerStateBegan) {
        NSLog(@"%s",__func__);
    }
    
}
-(void)tap:(UITapGestureRecognizer *)aGRer{
    NSLog(@"%s",__func__);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值