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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容