美文网首页
2018-04-24 仿微信的图片浏览器实现(一)

2018-04-24 仿微信的图片浏览器实现(一)

作者: 幸福晓杰2016 | 来源:发表于2018-04-24 17:45 被阅读11次

    本来想通过scroll+手势操作实现的,结果scrollView本身就有很多复杂的手势,所以这个方法失败告终。

    #pragma mark - gesture 手势操作
    //创建缩放手势
    -(void)createPinchGesture{
        for (UIImageView * vw in self.imageViewArr) {
            UIPinchGestureRecognizer *pinchGes  =[[UIPinchGestureRecognizer alloc]init];
            pinchGes.delegate = self;
            [pinchGes addTarget:self action:@selector(pinchGes:)];
            [vw addGestureRecognizer:pinchGes];
        }
    }
    -(void)pinchGes:(UIPinchGestureRecognizer *)ges{
        //比列
        CGFloat scale = ges.scale;
        //改变视图比列
        ges.view.transform = CGAffineTransformScale(ges.view.transform, scale, scale);
        //比列为1
        ges.scale = 1;
    }
    //创建旋转手势
    -(void)createRotataeGesture{
        for (UIImageView * vw in self.imageViewArr) {
            UIRotationGestureRecognizer *rotationGes = [[UIRotationGestureRecognizer alloc]init];
            rotationGes.delegate = self;
            [rotationGes addTarget:self action:@selector(rotGes:)];
            [vw addGestureRecognizer:rotationGes];
        }
    }
    
    -(void)rotGes:(UIRotationGestureRecognizer *)ges{
        ges.view.transform = CGAffineTransformRotate(ges.view.transform, ges.rotation);
        ges.rotation = 0;
    }
    //创建拖动手势 放大后才创建拖动手势。
    -(void)createPanGesture
    {
        for (UIImageView * vw in self.imageViewArr) {
            UIPanGestureRecognizer *panGse = [[UIPanGestureRecognizer alloc]init];
            panGse.delegate = self;
            [panGse addTarget:self action:@selector(panGes1:)];
            [vw addGestureRecognizer:panGse];
        }
    }
    
    -(void)panGes1:(UIPanGestureRecognizer *)ges
    {
        CGPoint point = [ges translationInView:ges.view];
        ges.view.transform = CGAffineTransformTranslate(ges.view.transform, point.x, point.y);
        //偏移量清零(这个事手势,如果每次手势调用都不清理会自动累加到下次,造成不精确,所以每次都要清理上次的偏移量,重新计算下次的,保证精确)这个没有经过准确的计算
        //就是回到原先位置,然后从新计算,不然会累积到下次来
        [ges setTranslation:CGPointZero inView:ges.view];
    }
    //和其他手势一起进行
    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
        return YES;
    }
    
    

    相关文章

      网友评论

          本文标题:2018-04-24 仿微信的图片浏览器实现(一)

          本文链接:https://www.haomeiwen.com/subject/koijlftx.html