如何在UIScrollview中处理Pinch和Pan Gesture UIView?

时间:2017-11-17 04:29:32

标签: ios objective-c uiscrollview uipangesturerecognizer uipinchgesturerecognizer

任何人都可以告诉我如何在UIScrollview中处理Pinch和平移手势UIView。 我必须同时显示两个视频,并且可以在其上使用平移和捏手势。所以我在每个UIView上保留两个AVPlayer。然后我将UIView放在每个ScrollView中。 现在我需要甚至当我平移或捏UIView时它仍然保持在UIScrollView的边界内。因为当我淘汰它时,我可以将它移到UIScrollview之外。 这是我在github中的代码 https://github.com/longnh2604/CheckVideoZoom.git

  

平移手势

- (IBAction)handlePan1:(UIPanGestureRecognizer *)sender 
{
    CGPoint translation = [sender translationInView:self.view];
    sender.view.center = CGPointMake(sender.view.center.x + translation.x,
                                         sender.view.center.y + translation.y);
    [sender setTranslation:CGPointMake(0, 0) inView:self.view];
}
  

捏手势

- (void)twoFingerPinch1:(UIPinchGestureRecognizer *)recognizer
{
    static float initialDifference = 0.0;
    static float oldScale = 1.0;

    if (recognizer.state == UIGestureRecognizerStateBegan){
        initialDifference = oldScale - recognizer.scale;
    }

    CGFloat scale = oldScale - (oldScale - recognizer.scale) + initialDifference;

    viewVideo1.transform = CGAffineTransformScale(self.view.transform, scale, scale);

    oldScale = scale;

}

0 个答案:

没有答案