ios开发:手势

一、手势

    //点击手势
    UITapGestureRecognizer *tap
    //移动手势
    UIPanGestureRecognizer *pan
    //添加到视图上面
    [imageView addGestureRecognizer:pan];
#pragma mark - 移动手势的方法
- (void)pan:(UIPanGestureRecognizer *)pan{
    //手势的生命:began - changed - ended
    //判断手势的状态:state
    if (pan.state == UIGestureRecognizerStateBegan || pan.state == UIGestureRecognizerStateChanged) {
        //1、找到手势所在的view
        UIImageView *imageView = (UIImageView *)pan.view;
        //2、获取手势移动的位移
        CGPoint point = [pan translationInView:self.view];
        //3、更改imageView的位置
        imageView.center = CGPointMake(imageView.center.x + point.x, imageView.center.y + point.y);
        //4、手势的位移是会叠加的,需要把手势移动的位移归零
        //CGPointZero == CGPointMake(0,0)
        [pan setTranslation:CGPointZero inView:self.view];
    }
}
    //缩放手势
    UIPinchGestureRecognizer *pinch
    //旋转手势
    UIRotationGestureRecognizer *rotation

你可能感兴趣的:(ios开发:手势)