五种常用手势

– (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__);
}

    原文作者:五大常用算法
    原文地址: https://blog.csdn.net/ylm0302/article/details/13766327
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞