标签:ios   常用手势   
-(void)viewDidLoad
{
    [super viewDidLoad];
    imageView=[[UIImageView alloc] initWithFrame:CGRectMake(100, 150, 120, 120)];
    imageView.image=[UIImage imageNamed:@"2.jpg"];
    [self.view addSubview:imageView];
    [imageView release];
    imageView.userInteractionEnabled=YES;
    //-----添加手势——点击
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];//tap
 :点击|gesture:手势|Recognizer:承认者/响应者
    [imageView addGestureRecognizer:tap];
    tap.numberOfTapsRequired=2;//需要点击几次?
 required:需求
    tap.numberOfTouchesRequired=2;//几个触点啊? touches:触点
    [tap release];
    //-----添加手势——平移
    UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];//pan:
    [imageView addGestureRecognizer:pan];
    [pan release];
    //------添加手势——旋转
    UIRotationGestureRecognizer * rotation=[[UIRotationGestureRecognizer alloc] initWithTarget:selfaction:@selector(rotation:)];//Rotation:旋转
    [imageView addGestureRecognizer:rotation];
    //------添加手势——收缩
    UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
    [imageView addGestureRecognizer:pinch];
    [pinch release];
    [rotation release];
}
 //收缩实现——//bounds:界限 |scale
 :比例 友情提示,bounds 中心点不改变X,Y轴的距离,只改变长宽。
-(void)pinch:(UIPinchGestureRecognizer *)pinch
{
    imageView.bounds=CGRectMake(0, 0, imageView.bounds.size.width*pinch.scale,imageView.bounds.size.height*pinch.scale);//bounds:界限 |scale
 :比例 友情提示,bounds 中心点不改变X,Y轴的距离,只改变长宽。
    pinch.scale=1.0;
}
-(void)pan:(UIPanGestureRecognizer *)pan
{
    CGPoint point=[pan translationInView:self.view];//
 translation :平移 获取相对坐标原点的坐标
    NSLog(@"%f,%f",point.x,point.y);
    imageView.center=CGPointMake(imageView.center.x+point.x, imageView.center.y+point.y);
    [pan setTranslation:CGPointZero inView:self.view];//设置坐标原点位上次的坐标
}
   //旋转
-(void)rotation:(UIRotationGestureRecognizer *)rotation
{
    imageView.transform=CGAffineTransformMakeRotation(finRotation+rotation.rotation);//transform
 :弧度改变 |affine:仿射  弧度改变
    if(rotation.state==UIGestureRecognizerStateEnded)//监听响应者的状态,判断是否结束
    {
        finRotation+=rotation.rotation;//弧度修改
    }
    NSLog(@"元方你怎么看?%f",rotation.rotation);
}
-(void)tap:(UITapGestureRecognizer *)tap
{
    NSLog(@"tap");
}
iOS 手势
标签:ios   常用手势   
原文地址:http://blog.csdn.net/sun_winter/article/details/45167741