Question

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

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top