iOS开发经验总结

ios开发:手势

2017-07-30  本文已影响1人  SadMine

一、手势

    //点击手势
    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
上一篇下一篇

猜你喜欢

热点阅读