Question

I need to add an UIPanGestureRecognizer to swipe horizontally 3 views. How can I add UIPangesture only horizontally to an UIView?

Was it helpful?

Solution

When you use a pan gesture recognizer, you usually have some code that looks something like this:

CGPoint translate = [sender translationInView:self.view];
    CGRect newFrame = self.currentViewFrame;
    newFrame.origin.x += translate.x;
    newFrame.origin.y += translate.y;
    self.touched.frame = newFrame; // touched is the view I'm dragging

If you just leave out the line, newFrame.origin.y += translate.y, then it will only pan in the horizontal direction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top